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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

DAX formula - in a new column

Hi, 

 

I have the below table for which I want to retrieve this Output column, using a DAX formula. The logic should be the following: If for the same month & item if I have value 1 for more than one entity , retrive 1 only for the last entity based on Date column and for the first one put 0. For the rest, including the same entity, leave the Value column. Basically, in my exemple, the only change should be done for the first item only because for the Item A, Month May I have the 1 value for 2 different entities and the one that should keep the 1 value should be the last one, meaning MNO, for the other (XYZ) we should have 0 in May 2020. 

 

Can someone provide me an urgent answer, please? 

 

Thank yoooou!

MonthDateItemEntityValueOutput
May-205/1/2020AXYZ10
May-205/1/2020BXYZ11
May-205/3/2020AMNO11
May-205/3/2020AXYZ00
May-205/4/2020CXYZ11
Jun-206/4/2020AXYZ11
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous - I did it like below. PBIX is attached. Let me know if it works for your larger dataset.

Output = 
    VAR __Count = 
        COUNTROWS(
            SUMMARIZE(
                FILTER('Table',[Month] = EARLIER('Table'[Month]) && [Item] = EARLIER('Table'[Item]) && [Value] = 1),
                [Entity]
            )
        )
RETURN
    IF(__Count <= 1 || [Value] = 0,[Value],
            VAR __LastDate = MAXX(FILTER('Table',[Month] = EARLIER('Table'[Month]) && [Item] = EARLIER('Table'[Item]) && [Value] = 1),[Date])
        RETURN
            IF([Date] = __LastDate,1,0)
    )

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@Anonymous - I did it like below. PBIX is attached. Let me know if it works for your larger dataset.

Output = 
    VAR __Count = 
        COUNTROWS(
            SUMMARIZE(
                FILTER('Table',[Month] = EARLIER('Table'[Month]) && [Item] = EARLIER('Table'[Item]) && [Value] = 1),
                [Entity]
            )
        )
RETURN
    IF(__Count <= 1 || [Value] = 0,[Value],
            VAR __LastDate = MAXX(FILTER('Table',[Month] = EARLIER('Table'[Month]) && [Item] = EARLIER('Table'[Item]) && [Value] = 1),[Date])
        RETURN
            IF([Date] = __LastDate,1,0)
    )

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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