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
Mass
New Member

QTD as of previous month

I want to display QTD as of previous month means In june, the value should be only for Apr and May. Can anyone give me the formula. The below one is giving QTD not as of previous month

 

QTD PrevMonth =
CALCULATE (
    [Total Production],
    FILTER (
        ALL ( 'Months'[Month] ),
        'Months'[Month] <= MAX(Months[Month]) )
    )

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@Mass,

In your scenario, firstly, create a Year table listing years(2012,2013,2014,2015,2016,2017,2018…), create a Month Table listing months(1,2,3…12), but don’t create any relationship between the Year/Month table and your original table.

Secondly, in your original table(take Sheet4 table for example), create a year column and month column using following DAX.

Year = YEAR(Sheet4[DateKey])
Month = MONTH(Sheet4[DateKey])

Then create a measure in your original table using DAX below.

CheckMeasure = IF(MAX(Sheet4[year])=MAX(Year[Year])&& MAX(Sheet4[Month])<MAX(Month[Month])&&MAX(Sheet4[Month])>=MAX(Month[Month])-2,1,0)

Thirdly, create a slicer using your Year table, create a slicer using your Month table and drag the CheckMeasure to the Visual level filters of your visual and filter the measure to 1 only. This way, when you select year and month in the slicers, the visual will show value for previous two months value. You can review the following example for more details.
1.JPG

 



Regards,

Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuezhe-msft
Employee
Employee

@Mass,

In your scenario, firstly, create a Year table listing years(2012,2013,2014,2015,2016,2017,2018…), create a Month Table listing months(1,2,3…12), but don’t create any relationship between the Year/Month table and your original table.

Secondly, in your original table(take Sheet4 table for example), create a year column and month column using following DAX.

Year = YEAR(Sheet4[DateKey])
Month = MONTH(Sheet4[DateKey])

Then create a measure in your original table using DAX below.

CheckMeasure = IF(MAX(Sheet4[year])=MAX(Year[Year])&& MAX(Sheet4[Month])<MAX(Month[Month])&&MAX(Sheet4[Month])>=MAX(Month[Month])-2,1,0)

Thirdly, create a slicer using your Year table, create a slicer using your Month table and drag the CheckMeasure to the Visual level filters of your visual and filter the measure to 1 only. This way, when you select year and month in the slicers, the visual will show value for previous two months value. You can review the following example for more details.
1.JPG

 



Regards,

Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.