Created
June 23, 2023 21:15
-
-
Save tirnovar/0015222371d457ffb8082f1751f78421 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| svgBarchart = | |
| VAR _barSpaceSize = 3 | |
| VAR _svgDeclaration = "data:image/svg+xml;utf8," | |
| VAR _svgHeader = "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 300 300'>" | |
| VAR _svgEnd = "</svg>" | |
| VAR _green = "#95BB4B" | |
| VAR _red = "#A41515" | |
| VAR _grey = "#E6E6E6" | |
| VAR _valuesTbl = | |
| ADDCOLUMNS( | |
| SUMMARIZE('Table', 'Table'[Date]), | |
| "@val", [<My-MEASURE>], | |
| "@rowNum", ROWNUMBER('Table', ORDERBY([Date],ASC)) | |
| ) | |
| VAR _maxDate = MAXX(_valuesTbl,[Date]) | |
| VAR _minDate = MINX(_valuesTbl,[Date]) | |
| VAR _maxx = MAXX(_valuesTbl, [@val]) | |
| VAR _counter = COUNTROWS(_valuesTbl) | |
| VAR _firstValue = MINX(FILTER(_valuesTbl,[Date]=_minDate),[@val]) | |
| VAR _lastValue = MAXX(FILTER(_valuesTbl,[Date]=_maxDate),[@val]) | |
| VAR _Diff = _lastValue-_firstValue | |
| VAR _Div = FORMAT(DIVIDE(_lastValue,_firstValue)-1,"0.0%") | |
| VAR _textColor = IF(_Diff>=0, _green,_red) | |
| VAR _initialText = | |
| "<text y='5%' font-weight='bold' font-size='15px' font-family='Segoe UI' dominant-baseline='middle' text-anchor='start' fill='#808080'> | |
| <tspan fill='"&_textColor&"'>" | |
| & _Diff & | |
| "</tspan> ( | |
| <tspan fill='"&_textColor&"'>" | |
| & _Div & | |
| "</tspan>) | |
| </text>" | |
| VAR _supportText = | |
| "<text y='12.5%' font-size='15px' font-family='Segoe UI' dominant-baseline='middle' text-anchor='start' fill='#808080'> | |
| vs start of period: "&_firstValue&" | |
| </text>" | |
| VAR _bars = | |
| CONCATENATEX( | |
| _valuesTbl, | |
| VAR _colorOfBar = IF([Date]=_maxDate,_green,_grey) | |
| VAR _startOfBar = ROUND(DIVIDE([@val],_maxx)*75,1) | |
| VAR _positionCounter = (([@rowNum]-1)*_barSpaceSize)+(_barSize*[@rowNum]) | |
| RETURN | |
| "<rect x='"&_positionCounter&"%' y='"&90-_startOfBar&"%' width='"&_barSpaceSize&"%' height='"&_startOfBar&"%' fill='"&_colorOfBar&"' opacity='1' style='outline: none;'></rect>") | |
| VAR _chartText = | |
| "<text y='92.5%' font-size='10px' font-family='Segoe UI' dominant-baseline='hanging' fill='#808080'> | |
| <tspan x='"&_barSize&"%' text-anchor='start'>" | |
| & FORMAT(_minDate,"dd/mm/yy") & | |
| "</tspan> | |
| <tspan x='"&101&"%' text-anchor='end'>" | |
| & FORMAT(_maxDate,"dd/mm/yy") & | |
| "</tspan> | |
| </text>" | |
| VAR _result = | |
| _svgDeclaration & | |
| _svgHeader & | |
| _initialText & | |
| _supportText & | |
| _bars & | |
| _chartText & | |
| _svgEnd | |
| RETURN _result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment