The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
How can I create YOY calculations when I have separate rows for YTD and LYTD. This also has to work with data filter that lets user choose b/w YTD, LYTD ,Rolling 12 months current, Rolling 12 months prior. | |
Data Structure | |
Time Period | Amount |
YTD | 1200 |
LTYD | 1000 |
Rolling 12 month CY | 800 |
Rolling 12 months PY | 900 |
I want to create a KPI with YoY values with a time period filter consisting of above 4 values. Note, we are not getting date level granular data in Power BI and creating these calcuations within SQL itself. |
I'm not too sure what the final visual you need is, but see if this helps.
Firstly, create an independent table with the periods and an order column for simplicity purposes)
Dim Period =
ADDCOLUMNS (
DISTINCT ( FactTable[Time Period] ),
"Order",
SWITCH (
FactTable[Time Period],
"YTD", 1,
"LTYD", 2,
"Rolling 12 month CY", 3,
"Rolling 12 months PY", 4
)
)
Again for simplicity purposes, add an order column to the fact table:
Now create a measure for each metric following this pattern:
YTD =
CALCULATE ( [Sum Amount], FILTER ( ALL ( 'FactTable' ), FactTable[Order] = 1 ) )
and for the comparisons, again for each metric:
YTD vs Selected period =
VAR _SP =
SWITCH (
SELECTEDVALUE ( 'Dim Period'[Order] ),
1, [YTD],
2, [LTYD],
3, [Rolling 12 month CY],
4, [Rolling 12 month PY]
)
RETURN
DIVIDE ( [YTD], _SP )
To get:
I've attached the sample PBIX file
Proud to be a Super User!
Paul on Linkedin.
User | Count |
---|---|
65 | |
60 | |
55 | |
54 | |
31 |
User | Count |
---|---|
180 | |
88 | |
72 | |
48 | |
46 |