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
Avivek
Post Partisan
Post Partisan

dax for 12 months sales needs to filter on multiple data's

I have a requirement to show the last 12 month sales for which the dax used is 

Last N Month Sales =
---------------------------------------------------------
VAR _selectedAltYear =
SELECTEDVALUE( 'To Year'[Year Number])
-----------------------------------------------------
//new date table
VAR __rlvntDateTable =
CALCULATETABLE(
'Date',
FILTER('Date','Date'[Date]>= edate([Max Date of To Year],-12) && 'Date'[Date]<= [Max Date of To Year])
)
---------------------------------------------------------
VAR _altsalesamount =
CALCULATE( [Sales Amount], __rlvntDateTable )
 
RETURN
_altsalesamount
 
It works fine with the To Year slicer, however we also have system and segment slicer. For eg. If we select the To Year as 2022 then it shows sales from Feb 2021 to Dec 2021. But if we select some system or segment name who might not have had sales in the period Feb 2021 to Dec 2021then they show sales only for the month in the period Feb 2021 to Dec 2021 where the sales have happened for the given system or segment. 
Is it possible to filter the data based on all the three slicers, say To Year, System and Segment.
1 ACCEPTED SOLUTION

Hi, @Avivek 

 

Try to combine this formula into your code:

Year =
IF (
    SELECTEDVALUE ( 'Table'[year] = "Current" ),
    YEAR ( 'Table'[Date] ) = YEAR ( TODAY () ),
    YEAR ( 'Table'[Date] )
)

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

View solution in original post

3 REPLIES 3
ALLUREAN
Solution Sage
Solution Sage

Hi, @Avivek 

 

Try this:

 

Last 12 Months =
CALCULATE (
[Sales Amount],
DATESINPERIOD (
'Date'[Date], -- returns period from date column
MAX ( 'Date'[Date] ), -- starting from MAX date
-12, -- shifting it back 12 intervals
MONTH -- each interval being a month
)
)

 

 

Did I answer your question? Please Like and Mark my post as a solution if it solves your issue. Thanks.

Appreciate your Kudos !!!

https://allure-analytics.com/

https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA

https://www.linkedin.com/company/77757292/




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




Thankyou @ALLUREAN , the measure seems to work in general. But we have few more requirements that needs to be taken into account. We need to have a date slicer which was earlier from To Year  table. But it seems the user wants to have a current year slicer instead of the usual To Year slicer. The current year slicer would show the current year by default by that slicer.

But since I have To Year as a filter condition in the measure itself, I am unable to use Current Year column as a slicer for this page. Is there a way to show the current year below like shown in the image without changing anything in the model.

Avivek_0-1643089788742.png

 

Hi, @Avivek 

 

Try to combine this formula into your code:

Year =
IF (
    SELECTEDVALUE ( 'Table'[year] = "Current" ),
    YEAR ( 'Table'[Date] ) = YEAR ( TODAY () ),
    YEAR ( 'Table'[Date] )
)

Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

Best Regards,
Community Support Team _ Janey

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.