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
trabass
Frequent Visitor

DAX Calculation Help - Appending and filtering records

I'm stuck figuring out the dax formula to achieve the following.

 

Have a table of data (Tasks) which I report off.  Been asked to take quarterly snapshots (Tasks Archive) to "lock" the values report in those quarters.  However, data in future quarters comes from the "Tasks Table".

 

I've taken the two tables and appended them together.  Now there are duplicate rows.  My pseudo logic that I'm trying to convert to DAX is as follows:

 

If Tasks Table (Task Finish Date) is less than the Tasks Archive Table (Archive Date) then return Tasks Archive Table Row values Except where Tasks Table has values different Tasks Archive Table Then

report row as exception to be fixed.

 

If Tasks Table (Task Finish Date) is greater than the Tasks Archive Table (Archive Date) then return Tasks Table Row values

 

SourceTasks IDArchive DateTasks Finish DateValueRow to Report (Y / N)
Tasks Archive101/02/201831/01/201810Y
Tasks1 31/01/201810N
Tasks Archive201/02/201825/01/2018 N
Tasks2 25/01/20185Exception
Tasks Archive301/02/201830/03/2018 N
Tasks3 30/03/201810Y
1 ACCEPTED SOLUTION

Hi @trabass

 

I think there is a way in QUERY Editor to get the SOURCE TABLE name.

 

Nevertheless...since it appears that Archive Date is Blank for TASKS table... you may add this calculated column to get the source

 

Source =
IF ( ISBLANK ( MergedTable[Archive Date] ), "Tasks", "Tasks Archive" )

source.png


Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
Zubair_Muhammad
Community Champion
Community Champion

@trabass

 

Try this calculated column.

 

Assuming your Table Name is "MergedTable"

 

Row to Report =
VAR FinishDate_is_Earlier =
    CALCULATE (
        FIRSTNONBLANK ( MergedTable[Tasks Finish Date], 1 ),
        FILTER (
            ALLEXCEPT ( MergedTable, MergedTable[Tasks ID] ),
            MergedTable[Source] = "Tasks Archive"
        )
    )
        < CALCULATE (
            FIRSTNONBLANK ( MergedTable[Archive Date], 1 ),
            FILTER (
                ALLEXCEPT ( MergedTable, MergedTable[Tasks ID] ),
                MergedTable[Source] = "Tasks Archive"
            )
        )
VAR Values_are_same =
    CALCULATE (
        SUM ( MergedTable[Value] ),
        FILTER (
            ALLEXCEPT ( MergedTable, MergedTable[Tasks ID] ),
            MergedTable[Source] = "Tasks Archive"
        )
    )
        = CALCULATE (
            SUM ( MergedTable[Value] ),
            FILTER (
                ALLEXCEPT ( MergedTable, MergedTable[Tasks ID] ),
                MergedTable[Source] = "Tasks"
            )
        )
VAR Exception_Check =
    IF (
        FinishDate_is_Earlier
            && Values_are_same = FALSE ()
            && MergedTable[Source] = "Tasks",
        "Exception"
    )
RETURN
    IF (
        Exception_Check = "Exception",
        "Exception",
        IF (
            FinishDate_is_Earlier && Values_are_same
                && MergedTable[Source] = "Tasks Archive",
            "Y",
            IF (
                FinishDate_is_Earlier = FALSE ()
                    && Values_are_same = FALSE ()
                    && MergedTable[Source] = "Tasks",
                "Y",
                "N"
            )
        )
    )

Regards
Zubair

Please try my custom visuals

@trabass

 

daxpuz.png

 


Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad

 

Thank you very much for the reply.  I didn't know about using variables in dax - learning slowly...

 

I shouldn't of included "Source" as an example column.  Unless when you do an append can you add a column that identifies which table the row of data was appended from?

 

Working on changing the formula you provided (thnks). 

Hi @trabass

 

I think there is a way in QUERY Editor to get the SOURCE TABLE name.

 

Nevertheless...since it appears that Archive Date is Blank for TASKS table... you may add this calculated column to get the source

 

Source =
IF ( ISBLANK ( MergedTable[Archive Date] ), "Tasks", "Tasks Archive" )

source.png


Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad Thanks very much for your help.  Didn't think of capturing the source that way, seems to easy now.

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.