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

Filtering of VAR table by value in matrix

Hi, 
I have created VAR table named JoinedTableX and in final part of calculation I need to filter its columns by values in matrix vizual (rows, columns).
And I don't know how to do that, so pls advise.

Sample table 

 

 

 

 

Duration Between Selected Folders TEST =
VAR MinCalDate =
    MIN ( 'Calendar'[Date] )
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR CaseIDX =
    VALUES ( Case_History_Summary[CaseID] )
VAR Folders =
    VALUES ( Case_History_Summary[Folder] )
VAR NextFolders =
    VALUES ( Case_History_Summary[NextFolder] )
VAR LastCaseHistoryIDForNextFolder =
    GROUPBY (
        FILTER (
            ALL ( Case_History_Summary ),
            MinCalDate <= Case_History_Summary[DatePST]
                && MaxDate >= Case_History_Summary[NextDatePST]
                && Case_History_Summary[CaseID]
                IN CaseIDX
                && Case_History_Summary[casehistoryid] <> Case_History_Summary[NextCaseHistoryID]
        ),
        Case_History_Summary[CaseID],
        Case_History_Summary[NextFolder],
        "Last casehistoryid", MAXX ( CURRENTGROUP (), [NextCaseHistoryID] ),
        "LastDate", MAXX ( CURRENTGROUP (), [NextDatePST] )
    )
VAR Table_FirstEntry =
    GROUPBY (
        FILTER (
            ALL ( Case_History_Summary ),
            MinCalDate <= Case_History_Summary[DatePST]
                && MaxDate >= Case_History_Summary[NextDatePST]
                && Case_History_Summary[CaseID]
                IN CaseIDX
                && Case_History_Summary[casehistoryid] <> Case_History_Summary[NextCaseHistoryID]
                && Case_History_Summary[NewToFolder] = 1
        ),
        Case_History_Summary[CaseID],
        Case_History_Summary[Folder],
        "First casehistoryid", MAXX ( CURRENTGROUP (), Case_History_Summary[casehistoryid] ),
        "FirstDate", MAXX ( CURRENTGROUP (), Case_History_Summary[DatePST] )
    )
VAR JoinedTable =
    FILTER (
        NATURALLEFTOUTERJOIN ( Table_FirstEntry, LastCaseHistoryIDForNextFolder ),
        [Last casehistoryid] > [First casehistoryid]
    )
VAR JoinedTableX =
    ADDCOLUMNS (
        JoinedTable,
        "DURATION", DATEDIFF ( [FirstDate], [LastDate], DAY ),
        "CaseIDXX", CALCULATE ( VALUES ( Case_History_Summary[CaseID] ) ),
        "FolderXX", CALCULATE ( VALUES ( Case_History_Summary[Folder] ) ),
        "NextFolderXX", CALCULATE ( VALUES ( Case_History_Summary[NextFolder] ) )
    )
RETURN
    SUMX (
        FILTER (
            JoinedTableX,
            //This part gives me problems
            [FolderXX]
                IN Folders
                && //Folders is selected value of Case_History_Summary[Folder] in matrix rows
            [NextFolderXX]
                IN NextFolders
                && //NextFolders is selected value of Case_History_Summary[NextFolder] in matrix columns
            [CaseIDXX]
                IN CaseIDX
        ),
        [DURATION]
    )

 

 

 

tomislav_0-1610647694503.pngtomislav_1-1610647720120.png

How it should look.

1 REPLY 1
lbendlin
Super User
Super User

Your measure is computed for every single cell in the visual, including the values area and the Totals row and column, and for the Grand Total.  This will automatically filter by the matrix's row/column intersection. You can use SELECTEDVALUE() but that will mess with the totals.

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.