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
Likhitha
Helper IV
Helper IV

How to calculate sales value when none of the month is selected and lag value is selected?

Hello All,

I'm having sales column.I want to calculate sales based on lag and month selection.I'm having 4 lags(1,2,3,4).

For example ,lag 1 means if my selected month is december then lag month should be november.

I created DAX for that logic and i got the solution.But the problem is if don't select any month and if selected lag,I want the  Output which is shown in the below image.(Lag selection is 1 and no month selection ,so my sales data has to be from Jan-Nov)

DAX:

Lag sales =
var currentmonth=MONTH(MAX(DateTable[Date]))
var Previousmonth= currentdate-SELECTEDVALUE(NewData[Month Lag Number])
var result=CALCULATE(SUM(NewData[Sales]),FILTER(NewData,MONTH(NewData[Date])=Previousmonth))
return
result

Lag Doubt.png

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Likhitha 

Create two tables, "lag table" and "month list", they have no relationship with other tables.

Then create a measure

lag sales =
VAR selected_m =
    SELECTEDVALUE ( 'month list'[month list] )
VAR selected_lag =
    SELECTEDVALUE ( 'lag table'[lag] )
VAR lagsales1 =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', MONTH ( [date] ) = selected_m - selected_lag )
    )
VAR lagsales2 =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', MONTH ( [date] ) <= ( 12 - selected_lag ) )
    )
RETURN
    IF ( ISFILTERED ( 'month list'[month list] ), lagsales1, lagsales2 )

Capture4.JPGCapture5.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @Likhitha 

Create two tables, "lag table" and "month list", they have no relationship with other tables.

Then create a measure

lag sales =
VAR selected_m =
    SELECTEDVALUE ( 'month list'[month list] )
VAR selected_lag =
    SELECTEDVALUE ( 'lag table'[lag] )
VAR lagsales1 =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', MONTH ( [date] ) = selected_m - selected_lag )
    )
VAR lagsales2 =
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER ( 'Table', MONTH ( [date] ) <= ( 12 - selected_lag ) )
    )
RETURN
    IF ( ISFILTERED ( 'month list'[month list] ), lagsales1, lagsales2 )

Capture4.JPGCapture5.JPG

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

@v-juanli-msft  Absolutely It's Working perfectly...Thanks a lot....Tank you very very much 🙂

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.