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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
liselotte
Helper I
Helper I

Flag duplicates in var table DAX

I have table ValueTable. I create a var table of ValueTable filtered by a date in Slicer, then I flag the duplicates of IDs with this query:

Flag =
var _table = ADDCOLUMNS(SUMMARIZE(
FILTER('fact_TimeTable',
('fact_ValueTable'[Date].[Date]=MAX('DateSlicer'[SelectedDate])) &&
('fact_ValueTable'[IsActive]=1)
)
, [ID]
, [Value]
)
, "IDx", [ID])
return
IF(CALCULATE(COUNTROWS(_table), ALLEXCEPT(_table, [IDx]))>1,TRUE(),FALSE())

 But I get an error of Cannot find name ID. Does anyone know why? Thank you in advance.

1 ACCEPTED SOLUTION
AmiraBedh
Most Valuable Professional
Most Valuable Professional

You're trying to flag rows where the ID appears more than once on the same date and when IsActive is 1, based on a selected date from DateSlicer.

Try the following :

 

Flag =
VAR SelectedDate = MAX('DateSlicer'[SelectedDate])
VAR IsActiveFilter = 1
VAR _table =
    FILTER(
        ALL('fact_ValueTable'), -- Consider using ALL to remove filters if necessary
        'fact_ValueTable'[Date] = SelectedDate &&
        'fact_ValueTable'[IsActive] = IsActiveFilter
    )
VAR _summarizedTable =
    SUMMARIZE(
        _table,
        'fact_ValueTable'[ID],
        "Count", COUNT('fact_ValueTable'[ID]) -- This adds a count of each ID
    )
RETURN
    IF(
        LOOKUPVALUE(
            _summarizedTable[Count],
            _summarizedTable[ID], EARLIER('fact_ValueTable'[ID])
        ) > 1,
        TRUE(),
        FALSE()
    )

 

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

3 REPLIES 3
AmiraBedh
Most Valuable Professional
Most Valuable Professional

You're trying to flag rows where the ID appears more than once on the same date and when IsActive is 1, based on a selected date from DateSlicer.

Try the following :

 

Flag =
VAR SelectedDate = MAX('DateSlicer'[SelectedDate])
VAR IsActiveFilter = 1
VAR _table =
    FILTER(
        ALL('fact_ValueTable'), -- Consider using ALL to remove filters if necessary
        'fact_ValueTable'[Date] = SelectedDate &&
        'fact_ValueTable'[IsActive] = IsActiveFilter
    )
VAR _summarizedTable =
    SUMMARIZE(
        _table,
        'fact_ValueTable'[ID],
        "Count", COUNT('fact_ValueTable'[ID]) -- This adds a count of each ID
    )
RETURN
    IF(
        LOOKUPVALUE(
            _summarizedTable[Count],
            _summarizedTable[ID], EARLIER('fact_ValueTable'[ID])
        ) > 1,
        TRUE(),
        FALSE()
    )

 

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Thank you a lot! It works like a charm!

AmiraBedh
Most Valuable Professional
Most Valuable Professional

Glad to help 😄


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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