Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone,
I'm having a hard time trying to find a solution with my LY and LYTD measures, because of our fiscal calendar doesn't start the 1st and ends on the 30/31st of every month. To better explain this, here is a screenshot of my different measures in separate visuals listed by calendar dates.
Now, here are my measures for each visual (left to right) :
Total Sales LY YTD VALID almost works for me, BUT it's not dynamic, meaning if I readd the filtering (2020), it won't show anything... What I'm going for is a measure that will allow me to get my result according to the slicers, for e.g.:
Solved! Go to Solution.
I have found the solution for any of you that might be interested :
Total Sales LY =
CALCULATE(
[Total Sales]
,FILTER(
ALL('Dim Date')
,'Dim Date'[Year]=VALUES('Dim Date'[Year])-1
&&'Dim Date'[Fiscal Period]<=MAX('Dim Date'[Fiscal Period] )
&&'Dim Date'[Fiscal Period]>=MIN('Dim Date'[Fiscal Period] )
)
)
Hi @ocabrejo,
Time intelligence function not suitable to nested or do customize with its calculation ranges.
In my opinion, I'd like to suggest you use DATE function to manually defined filter range to calculate, it should more agility and customizable. (YTD logic: records who has same year and date less than or equal to the current date)
YTD Measure =
VAR currDate =
MAX ( Table[Date] )
RETURN
CALCULATE (
SUM ( Table[Sales] ),
FILTER (
ALLSELECTED ( Table ),
YEAR ( [Date] ) = YEAR ( currDate )
&& [Date] <= currDate
)
)
If you confused about coding formula, please share some dummy data with a similar data structure to test.
Regards,
Xiaoxin Sheng
See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
The time intelligence functions will not work for me with a 4-5-4 calendar unfortunately.
Hi @ocabrejo,
I think you can consider write formula based on fiscal year and date fields, it also works for 4-5-4 calendar. (measure formula use the fiscal year to lock on the calculate date range and use date field as rolling condition)
YTD Measure =
VAR currDate =
MAX ( Table[Date] )
VAR currFYear =
MAX ( Calendar[Fiscal Year] )
VAR dateRange =
CALCULATETABLE (
VALUE ( Calendar[Date] ),
FILTER ( ALLSELECTED ( Calendar ), [Fiscal Year] = currFYear )
)
RETURN
CALCULATE (
SUM ( Table[Net Price] ),
FILTER ( ALLSELECTED ( Table ), [Date] IN dateRange && [Date] <= currDate )
)
LYTD Measure =
VAR currDate =
MAX ( Table[Date] )
VAR currFYear =
MAX ( Calendar[Fiscal Year] )
VAR dateRange =
CALCULATETABLE (
VALUE ( Calendar[Date] ),
FILTER ( ALLSELECTED ( Calendar ), [Fiscal Year] = currFYear-1 )
)
RETURN
CALCULATE (
SUM ( Table[Net Price] ),
FILTER ( ALLSELECTED ( Table ), [Date] IN dateRange && [Date] <= currDate )
)
Regards,
Xiaoxin Sheng
Thank you for responding @v-shex-msft Xiaoxin Sheng,
I've uploaded a dummy dataset and .pbix with the exact same Date dimension and the latest LY measure suggestion.
https://drive.google.com/drive/folders/14Q8SLMHOZV2qwaRtS9e2Qhvzouzu9o7A?usp=sharing
Let me know if you see anything that works out on your end.
Much appreciated
Oliver
HI @ocabrejo,
You can try below measure formula, I extract the 'fiscal start date' year as a condition to filter records:
LY Measure =
VAR currDate =
MAX ( 'Dim Date'[Date] )
VAR currFYear =
YEAR( MAX ( 'Dim Date'[FiscalStartDate] ))
VAR dateRange =
CALCULATETABLE (
VALUES('Dim Date'[Date]),
FILTER ( ALLSELECTED ( 'Dim Date' ), YEAR('Dim Date'[FiscalStartDate]) = currFYear-1 )
)
RETURN
CALCULATE (
SUM ( 'Fact Sales'[Total] ),
FILTER ( ALLSELECTED ( 'Fact Sales' ), 'Fact Sales'[Date] IN dateRange && 'Fact Sales'[Date] <= currDate )
)
Regards,
Xiaoxin Sheng
Hi @v-shex-msft ,
I've tried your new formula, but it's not working. I'm getting empty results/blanks.
I've updated the Google Drive.
Thank you
Oliver
I have found the solution for any of you that might be interested :
Total Sales LY =
CALCULATE(
[Total Sales]
,FILTER(
ALL('Dim Date')
,'Dim Date'[Year]=VALUES('Dim Date'[Year])-1
&&'Dim Date'[Fiscal Period]<=MAX('Dim Date'[Fiscal Period] )
&&'Dim Date'[Fiscal Period]>=MIN('Dim Date'[Fiscal Period] )
)
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
80 | |
67 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |