cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

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

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: DAX formula - in a new column

@Melisa123 - 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)
    )

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




View solution in original post

1 REPLY 1
Highlighted
Super User IV
Super User IV

Re: DAX formula - in a new column

@Melisa123 - 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)
    )

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




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

Proud to be a Super User!




View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors
Top Kudoed Authors