March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi there,
I currently have my dax code below that gives me the average over the previous 6 months which works correctly.
Image 2 would be 202201 - 202205 with the 5 months and so on with less months.
Is this possible?
Thankyou
1)
2)
Solved! Go to Solution.
Hi @lherbert501 ,
Based on your description, I have created a simple sample:
Please try:
First create a table for slicer:
Then change the slicer to single select:
Then create a measure like this:
Average =
var _a = VALUE( RIGHT( SELECTEDVALUE('For Slicer'[Value]),2))
return SUMX(FILTER('SalesOrders',MONTH([Date])<=_a),[Total Sales])/_a
Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @lherbert501 ,
Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.
Refer to:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @lherbert501 ,
Based on your description, I have created a simple sample:
Please try:
First create a table for slicer:
Then change the slicer to single select:
Then create a measure like this:
Average =
var _a = VALUE( RIGHT( SELECTEDVALUE('For Slicer'[Value]),2))
return SUMX(FILTER('SalesOrders',MONTH([Date])<=_a),[Total Sales])/_a
Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
In your dax function, check if the Month number is less than 6, then use StartOfYear('Date[Date]') in your date condition, otherwise use the current one(existing Dax that you wrote)
Hi @MahyarTF
Thanks for the reply.
How would you check if its less than 6 and where would the start of the year be in the query?
I think this is the part im struggling with?
Thanks in advance
Liam
If you have a Date dimension, you need to add the Number of months and then use it in your dax,
Otherwise, you could you the Right() function :
if (Right([Period], 2)>'06'), Date[Date] > Your Function && date[date] <= Max(Date[Date]), date[date] >= StartOfYear('Date[Date]') && date[date] <= Max(Date[Date])
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
127 | |
85 | |
69 | |
53 | |
44 |
User | Count |
---|---|
202 | |
106 | |
100 | |
64 | |
56 |