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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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