Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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 |
---|---|
78 | |
78 | |
59 | |
35 | |
33 |
User | Count |
---|---|
100 | |
62 | |
56 | |
47 | |
41 |