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.
My question sounds simple, but i have not been able to calculate the prior/previous month total using a dax formula. I have a formula that calulates the current/latest month total and here is the formula for the latest month:
Solved! Go to Solution.
Hi @Anonymous ,
I created some data:
Here are the steps you can follow:
1. Create measure.
ar_0_30 =
CALCULATE(SUM('Table'[M_BALN_POST]),FILTER(ALLSELECTED('Table'),
MAX('Table'[Report Date])>=DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))&&
MAX('Table'[Report Date])<=TODAY()
&&'Table'[Age Group - Discharge]="0-30"))
2. Click on the blank space of the page and place [Report Date] in the Filter to filter the entire page.
3. Result:
Total in the most recent month:
Filter type – Relative Date, Is in the last , 1, Month。
The results are displayed for the most recent month:
Total last month:
Filter type – Relative Date, Is in the last , 1, calendar months.
The results are shown as last month:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @Anonymous
There looks to be a lot of comments and potential solutions already provided, so my apologies if I am just adding to the confusion, however, can you try the below:
PriorMonthToDate =
VAR _CurMth = MONTH ( TODAY() )
VAR _CurYr = YEAR ( TODAY() )
VAR _CurDay = DAY ( MAX ( AR_Data[Report Date] ) )
VAR _LastDay = DATE ( _CurYr , _CurMth -1, _CurDay )
VAR _FirstDay = DATE ( _CurYr, _CurMth -1, 1 )
RETURN
CALCULATE ( SUM ( AR_Data[M_BALN_POST] ) , FILTER ( 'AR_Data' , AR_Data[Report Date] >= _FirstDay && AR_Data[Report Date] <= _LastDay ) , FILTER ( 'AR_Data' , AR_Data[Age Group - Discharge] = " 0-30" ) )
All the best!
Theo 🙂
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi @Anonymous ,
I created some data:
Here are the steps you can follow:
1. Create measure.
ar_0_30 =
CALCULATE(SUM('Table'[M_BALN_POST]),FILTER(ALLSELECTED('Table'),
MAX('Table'[Report Date])>=DATE(YEAR(TODAY()),MONTH(TODAY())-1,DAY(TODAY()))&&
MAX('Table'[Report Date])<=TODAY()
&&'Table'[Age Group - Discharge]="0-30"))
2. Click on the blank space of the page and place [Report Date] in the Filter to filter the entire page.
3. Result:
Total in the most recent month:
Filter type – Relative Date, Is in the last , 1, Month。
The results are displayed for the most recent month:
Total last month:
Filter type – Relative Date, Is in the last , 1, calendar months.
The results are shown as last month:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
form at of the report date. I dont think i can share the pbxi file.
Hi @Anonymous
You can try below code:-
PreviousMonth =
CALCULATE (
SUM ( AR_Data[M_BALN_POST] ),
FILTER (
AR_Data,
AR_Data[Report Date]
= MAX (
DATE ( YEAR ( AR_Data[Report Date] ), MONTH ( AR_Data[Report Date] ) - 1, DAY ( AR_Data[Report Date] ) )
)
),
FILTER ( AR_Data, ( AR_Data[Age Group - Discharge] = " 0-30" ) ) //change this filter condition according to your requirement
)
Thanks,
Samarth
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
thank you for that reply, it did not seem to work.
this is the error i am getting now
The MAX function only accepts a column reference as an argument.
Can you try below code:-
PreviousMonth =
CALCULATE (
SUM ( AR_Data[M_BALN_POST] ),
FILTER (
AR_Data,
AR_Data[Report Date]
= DATE ( MAX ( YEAR ( AR_Data[Report Date] ) ), MONTH ( MAX ( AR_Data[Report Date] ) ) - 1, DAY ( MAX ( AR_Data[Report Date] ) ) )
),
FILTER ( AR_Data, ( AR_Data[Age Group - Discharge] = " 0-30" ) )
)
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
same error
The MAX function only accepts a column reference as an argument.
Sorry my bad. This would work for sure 🙂
PreviousMonth =
CALCULATE (
SUM ( AR_Data[M_BALN_POST] ),
FILTER (
AR_Data,
AR_Data[Report Date]
= DATE ( YEAR ( MAX ( AR_Data[Report Date] ) ), MONTH ( MAX ( AR_Data[Report Date] ) ) - 1, DAY ( MAX ( AR_Data[Report Date] ) ) )
),
FILTER ( AR_Data, ( AR_Data[Age Group - Discharge] = " 0-30" ) )
)
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
There is no error, but the the ans shows blank. The formula has no errors.
Have you updated below condition in the formula as per your need?
FILTER ( AR_Data, ( AR_Data[Age Group - Discharge] = " 0-30" )
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
yes, i left the formula just the way it is, since i need that filter
Hope you have verified, you have data for previous month specific date?
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
yes, when i checked i do have data for the previous/prior month
Is it possible for you to share your PBIX file after removing confidential data?
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
how do i share the pbix file
You can upload it in a drive and share the link.
Best Regards,
Samarth
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin
I also have a field that is in the format of YYYYMM, Is there anyway that would work better
I dont think i can share that, it i going to take a lot of work to get rid of the confidential info.😟
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 |
---|---|
107 | |
98 | |
78 | |
65 | |
53 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |