Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I have used this post to create my custom predefined date ranges, which was really helpful btw.
https://community.powerbi.com/t5/Desktop/Custom-Predefined-Date-ranges/m-p/228667#M101979
Now I'm facing an issue when I try prior year calculations:
I understand that the issue is as @steph_io said:
"[...]it works to filter most measures, except those that is looking at prior period outside of the visual context.
Because the new DatePeriod table has already filtered the CreateDateTable, this formula will not go fetch the range of the prior year to give me a Year over Year value."
Does anybody know a solution or a workaround?
Solved! Go to Solution.
Hi @Anonymous ,
Prior year data is always filtered that is caused that there is a relationship between the Date Range table and Calendar table. For your requirement, we don't have to create any relationships among the Date Range table and others. We could use functions to implement filter.
I created a simple sample that you can reference.
Custom data change = var sel = SELECTEDVALUE('Date Range'[Period]) var mon_today = MONTH(TODAY()) var year_today = YEAR(TODAY()) var mon = CALCULATE(SUM(SalesPerItem[ Sales]), FILTER('Calendar', 'Calendar'[MONTH] = mon_today)) var year = CALCULATE(SUM(SalesPerItem[ Sales]), FILTER('Calendar', 'Calendar'[YEAR] = year_today)) return SWITCH(TRUE(), sel="This month",mon,sel="This year",year,SUM(SalesPerItem[ Sales]))
Last year = CALCULATE(SUM(SalesPerItem[ Sales]),SAMEPERIODLASTYEAR('Calendar'[Date]))
I attached my sample that you can try and check if is what you want. Hope it may help you.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.
Hi @Anonymous ,
Prior year data is always filtered that is caused that there is a relationship between the Date Range table and Calendar table. For your requirement, we don't have to create any relationships among the Date Range table and others. We could use functions to implement filter.
I created a simple sample that you can reference.
Custom data change = var sel = SELECTEDVALUE('Date Range'[Period]) var mon_today = MONTH(TODAY()) var year_today = YEAR(TODAY()) var mon = CALCULATE(SUM(SalesPerItem[ Sales]), FILTER('Calendar', 'Calendar'[MONTH] = mon_today)) var year = CALCULATE(SUM(SalesPerItem[ Sales]), FILTER('Calendar', 'Calendar'[YEAR] = year_today)) return SWITCH(TRUE(), sel="This month",mon,sel="This year",year,SUM(SalesPerItem[ Sales]))
Last year = CALCULATE(SUM(SalesPerItem[ Sales]),SAMEPERIODLASTYEAR('Calendar'[Date]))
I attached my sample that you can try and check if is what you want. Hope it may help you.
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Kudos are nice too.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
76 | |
61 | |
37 | |
33 |
User | Count |
---|---|
99 | |
56 | |
51 | |
42 | |
40 |