Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
snoh8r49
Frequent Visitor

Return time period of Min month and year up to last month

Currently I am able to create this for a card : 

DateText = IF(AND(SELECTEDVALUE(PERIOD_DIM[MTH],"All") ="All", SELECTEDVALUE(PERIOD_DIM[YR],"All")="All"),(MIN(PERIOD_DIM[MTH]) & "/" & MIN(PERIOD_DIM[YR]) &" - " & MAX(PERIOD_DIM[MTH]) & "/" & MAX(PERIOD_DIM[YR])),(SELECTEDVALUE(PERIOD_DIM[MTH],"All") & "-" & SELECTEDVALUE(PERIOD_DIM[YR],"All")))

 

However, the max month in my table is Sep of this year. I need to limit it to the previous month. I also want the slicer that is a Hierarchy Slicer built on MTH and YR to default to the previous month and year. That would then populate in the card. Is that possible?

1 ACCEPTED SOLUTION
snoh8r49
Frequent Visitor

I solved it with this:

DateText = IF(AND(SELECTEDVALUE(PERIOD_DIM[MTH],"All") ="All",  SELECTEDVALUE(PERIOD_DIM[YR],"All")="All"),MIN(PERIOD_DIM[MTH]) & "/" & MIN(PERIOD_DIM[YR]) & " - " & FORMAT((EOMONTH(TODAY(),-1)),"MMM/YYYY"),(SELECTEDVALUE(PERIOD_DIM[MTH],"All") &  "-" & SELECTEDVALUE(PERIOD_DIM[YR],"All")))
 
I didn't need the additional column after all. I had tried something like this before but until I saw @amitchandak's solution I didn't see where I was going wrong. 

View solution in original post

3 REPLIES 3
snoh8r49
Frequent Visitor

I solved it with this:

DateText = IF(AND(SELECTEDVALUE(PERIOD_DIM[MTH],"All") ="All",  SELECTEDVALUE(PERIOD_DIM[YR],"All")="All"),MIN(PERIOD_DIM[MTH]) & "/" & MIN(PERIOD_DIM[YR]) & " - " & FORMAT((EOMONTH(TODAY(),-1)),"MMM/YYYY"),(SELECTEDVALUE(PERIOD_DIM[MTH],"All") &  "-" & SELECTEDVALUE(PERIOD_DIM[YR],"All")))
 
I didn't need the additional column after all. I had tried something like this before but until I saw @amitchandak's solution I didn't see where I was going wrong. 
snoh8r49
Frequent Visitor

@amitchandak  How would I incorporate that to my measure?

amitchandak
Super User
Super User

@snoh8r49 , you need a column like this in your date table

 

Month Type = Switch( True(),
eomonth([Date],0) = eomonth(Today(),-1*month(Today())),"Last year Last Month" ,
eomonth([Date],0) = eomonth(Today(),-1),"Last Month" ,
eomonth([Date],0)= eomonth(Today(),0),"This Month" ,
Format([Date],"MMM-YYYY")
)

 

 

or

 

Month Type =

var _today =  max(Fact[Date])

Switch( True(),
eomonth([Date],0) = eomonth(_today ,-1*month(_today )),"Last year Last Month" ,
eomonth([Date],0) = eomonth(_today ,-1),"Last Month" ,
eomonth([Date],0)= eomonth(_today ,0),"This Month" ,
Format([Date],"MMM-YYYY")
)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.