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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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