Barcode & Jitter Scatter

Barcode Plot

_BarcodePlot = 
VAR AXISMAXRANGE = CALCULATE(MAX(financials[Gross Sales]), ALL(financials))
VAR AXISMINRANGE = CALCULATE(MIN(financials[Gross Sales]), ALL(financials))
VAR AXISRANGE = AXISMAXRANGE - AXISMINRANGE
VAR SVGWidth = 102
VAR SVGHeight = 20

RETURN
IF(
    HASONEVALUE(financials[Country]),
    "data:image/svg+xml;utf8," &
    "<svg width='" & SVGWidth & "' height='" & SVGHeight & "' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' overflow='visible'>" & 
    CONCATENATEX(
        financials, 
        "<line x1='" & (financials[Gross Sales] / AXISMAXRANGE * SVGWidth) & "' y1='1' x2='" & (financials[Gross Sales] / AXISMAXRANGE * SVGWidth) & "' y2='" & SVGHeight & "' stroke='blue' stroke-opacity='0.5' stroke-width='2' />",
        ""
    ) &
    "</svg>",
    BLANK()
)

Jittered Scatter Plot

_JitteredScatterPlot = 
VAR AXISMAXRANGE = CALCULATE(MAX(financials[Gross Sales]), ALL(financials))
VAR AXISMINRANGE = CALCULATE(MIN(financials[Gross Sales]), ALL(financials))
VAR AXISRANGE = AXISMAXRANGE - AXISMINRANGE
VAR SVGWidth = 102
VAR SVGHeight = 20
VAR JitterAmount = 5 // Adjust this value to control the amount of jitter

RETURN
IF(
    HASONEVALUE(financials[Country]),
    "data:image/svg+xml;utf8," &
    "<svg width='" & SVGWidth & "' height='" & SVGHeight & "' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' overflow='visible'>" & 
    CONCATENATEX(
        financials, 
        VAR Jitter = RAND() * JitterAmount - (JitterAmount / 2)
        RETURN 
        "<circle cx='" & (financials[Gross Sales] / AXISMAXRANGE * SVGWidth + Jitter) & "' cy='" & (SVGHeight / 2 + Jitter) & "' r='3' fill='blue' fill-opacity='0.5' />",
        ""
    ) &
    "</svg>",
    BLANK()
)

Leave a comment

Your email address will not be published. Required fields are marked *