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
Domval
New Member

How to calculatetable with filter expression from related table?

I am trying to create a new table in power bi model with calculate table function using related table as a filter for previous month.

Here is a working dax code just without the mentioned filter:

 

 TEST A = 
    CALCULATETABLE(
        SELECTCOLUMNS(
            FinancingContractHeader,
            "Customer Name", FinancingContractHeader[Customer Name],
            "Customer No", FinancingContractHeader[Customer No_],
            "Registration No", FinancingContractHeader[Registration No_],
            "Licence Plate No", FinancingContractHeader[Licence Plate No],
            "VIN", FinancingContractHeader[VIN],
            "Contract No", FinancingContractHeader[No_],
            "Status", FinancingContractHeader[Status Groups],
            "Product", FinancingContractHeader[Financing Product Type Code],
            "Start Date", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Start Date]),
            "End Date", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[End Date]),
            "Service Part", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Service Part]),
            "Finance Part", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Finance Part]),
            "Total Lease Payment", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Total Lease Payment]),
            "Year", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Year]),
            "Month", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Month]),
            "Date", SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Date])
        ),
        FinancingContractHeader[Financing Product Type Code] = "OL" ||
        FinancingContractHeader[Financing Product Type Code] = "SLB",
        FinancingContractHeader[Status Groups] = "Active" ||
        FinancingContractHeader[Status Groups] = "Archived" ||
        FinancingContractHeader[Status Groups] = "Closed" ||
        FinancingContractHeader[Status Groups] = "Settled"
)

 

 

Now I need to add condition 'Payment Calendar'[Date] is in previous month as a filter.

So I need to add after the last row something like:

 

PREVIOUSMONTH(SELECTCOLUMNS(RELATEDTABLE('Payment Calendar'),'Payment Calendar'[Date]))

 

 but this syntax is wrong and I also can not use selectcolumns function inside the filter expression in calculatetable function. Adding filter function in the beggining also doesnt work. Also tried chatGTP which suggested wrong code starting with the last row mention earlier:

 

FinancingContractHeader[Status Groups] = "Settled"
    ),
    YEAR('Payment Calendar'[Date]) = YEAR(TODAY()) &&
    MONTH('Payment Calendar'[Date]) = MONTH(TODAY()) - 1

 

 Any suggestion please?

0 REPLIES 0

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.