Forum Discussion
DAX Applying Measure in Current Month
As I understand, you only ever want to see 1 month of data. If the user doesn't select any period, you want the report to simulate as if the user had selected the latest month (as opposed to June hard coded). If a month is selected, then show at month. Regardless of anything else, only ever show one month. Is that correct?
Exactly!
This report is a stock analysis, so don't make sense in my report to allow more than one month selection.
Thanks.
- MattAllington10 years agoCommunity Champion
Ok. So technically we say "you want to select the last month in the current filter context". To do this, I would normally first ensure
- i had a calendar table
- the calendar table had a month ID column to uniquely identify each month in consecutive order
- Then write the following measure
=calculate(COUNTROWS(V_F_ASSETS), max(calendar[monthID]))
read about out calendar tables here http://exceleratorbi.com.au/power-pivot-calendar-tables/
- diogormatas10 years agoFrequent Visitor
MattAllington wrote:Ok. So technically we say "you want to select the last month in the current filter context". To do this, I would normally first ensure
- i had a calendar table
- the calendar table had a month ID column to uniquely identify each month in consecutive order
- Then write the following measure
=calculate(COUNTROWS(V_F_ASSETS), max(calendar[monthID]))
read about out calendar tables here http://exceleratorbi.com.au/power-pivot-calendar-tables/
Hi, thanks for your help.
Your sugestion return the error "A function 'MAX' has been used in a True/False expression" and after i tried this way:Current Month # Assets v4 = calculate(COUNTROWS(V_F_ASSETS), filter(V_DIM_TIME,max(V_DIM_TIME[COD_MONTH_ID])))
Where COD_MONTH_ID is the concantenation between yyyymm, to have a unique MONTH ID.
But the output was strange and I could not interpret it.
One last try, it matters the place/table that i added my meausure? This measure relates data from FACT and TIME tables.
Thanks all. - MattAllington10 years agoCommunity Champion
Wow, did I write that measure?! Sorry about that.
Try this
=
CALCULATE (
COUNTROWS ( V_F_ASSETS ),
FILTER ( ALL ( calendar ), calendar[monthID] = MAX ( calendar[monthID] ) )
) - diogormatas10 years agoFrequent Visitor
MattAllington wrote:Wow, did I write that measure?! Sorry about that.
Try this
=
CALCULATE (
COUNTROWS ( V_F_ASSETS ),
FILTER ( ALL ( calendar ), calendar[monthID] = MAX ( calendar[monthID] ) )
)MattAllington
I fully agree with your approach!
But this one replicate my 1st measure behaviour when i don't select any month in the slicer i.e. it works on a card visualization (Aggregated data), but it doesn't work when I use it on a table with any other dimension.
The reason is the same, it doesn't return the data for MaxMonth, it returns the MaxMonth data for each specific dimension value. So in some cases instead of return 0 to June data, the measure is returning 2 assets in May.
Thanks.