Last active
April 8, 2025 07:56
-
-
Save deldersveld/62523ca8350ac97797131560cb317677 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
Sparkline Line = | |
// Static line color - use %23 instead of # for Firefox compatibility | |
VAR LineColor = "%2301B8AA" | |
// "Date" field used in this example along the X axis | |
VAR XMinDate = MIN('Table'[Date]) | |
VAR XMaxDate = MAX('Table'[Date]) | |
// Obtain overall min and overall max measure values when evaluated for each date | |
VAR YMinValue = MINX(VALUES('Table'[Date]),CALCULATE([Measure Value])) | |
VAR YMaxValue = MAXX(VALUES('Table'[Date]),CALCULATE([Measure Value])) | |
// Build table of X & Y coordinates and fit to 100 x 100 viewbox | |
VAR SparklineTable = ADDCOLUMNS( | |
SUMMARIZE('Table','Table'[Date]), | |
"X",INT(100 * DIVIDE('Table'[Date] - XMinDate, XMaxDate - XMinDate)), | |
"Y",INT(100 * DIVIDE([Measure Value] - YMinValue,YMaxValue - YMinValue))) | |
// Concatenate X & Y coordinates to build the sparkline | |
VAR Lines = CONCATENATEX(SparklineTable,[X] & "," & 100-[Y]," ", [Date]) | |
// Add to SVG, and verify Data Category is set to Image URL for this measure | |
VAR SVGImageURL = IF(HASONEVALUE('Table'[Category]), | |
"data:image/svg+xml;utf8," & | |
"<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 100 100'>" & | |
"<polyline fill='none' stroke='" & LineColor & | |
"' stroke-width='3' points='" & Lines & | |
"'/></svg>", | |
BLANK()) | |
RETURN SVGImageURL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@powerlars, late but I see you asked the same thing I figured out today. I simply added a column with a day ordinal in my date dimension:
DataDay = 'Date'[Date]-MIN('Date'[Date])
After that, each granular level can be chosen (in the example below it's by quarter) and properly spaced: