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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Domval
Regular Visitor

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.