cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Diego-mx
Advocate I
Advocate I

Call column from calculated VAR table


I am using a virtual relation to filter entries in my Cars table. 

Purchased_SoFar ...
RETURN CALCULATE( COUNT('Cars'[car_id]) ), TREATAS( VALUES( 'SubCalendar'[a_date]), 'Cars'[purchase_date]) )

However I need to filter the Calendar table beforehand for the SoFar part...   

VAR SubCalendar = CALCULATETABLE('Calendar', 
    FILTER( ALL('Calendar'[date_day]), 
        'Calendar'[date_day] <= MAX('Calendar'[date_day]))))

(together with other slicer values like [month_date]. )

I am getting an error for not finding the table SubCalendar. 


How can I call the columns from the calculated table?
Thanks


1 ACCEPTED SOLUTION

Hello, thank you for the answer. 
In the formula [date_day] refers to the day of the month but I also have [a_date] which would be the one related to [purchased_date].

I have tried your suggested answer, but TREATAS won't recognize the corresponding column to match with my related column. 

I actually figured it out via an extra SELECTCOLUMNS

VAR Subtable = SELECTCOLUMNS(
    CALCULATETABLE( 'Calendar', 
        FILTER(ALL('Calendar'[date_day]), 'Calendar'[date_day] <= MAX( 'Calendar'[date_day]) )), 
    "a_date", [a_date] )

Thanks. 

View solution in original post

2 REPLIES 2
v-jiascu-msft
Microsoft
Microsoft

Hi @Diego-mx,

 

The treatas-function works with two unrelated tables. 

1. Are there any relationships between the two tables? If so, You don't need a VAR parameter.

 

Measure =
CALCULATE (
    COUNT ( 'Cars'[car_id] ),
    FILTER (
        ALL ( 'Calendar'[date_day] ),
        'Calendar'[date_day] <= MAX ( 'Calendar'[date_day] )
    )
)

 

2. If you can't establish a relationship, the formula could be like below.

 

Measure =
CALCULATE (
    COUNT ( 'Cars'[car_id] ),
    TREATAS (
        FILTER ( 'Calendar', 'Calendar'[date_day] <= MAX ( 'Calendar'[date_day] ) ),
        'Cars'[purchase_date]
    )
)

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello, thank you for the answer. 
In the formula [date_day] refers to the day of the month but I also have [a_date] which would be the one related to [purchased_date].

I have tried your suggested answer, but TREATAS won't recognize the corresponding column to match with my related column. 

I actually figured it out via an extra SELECTCOLUMNS

VAR Subtable = SELECTCOLUMNS(
    CALCULATETABLE( 'Calendar', 
        FILTER(ALL('Calendar'[date_day]), 'Calendar'[date_day] <= MAX( 'Calendar'[date_day]) )), 
    "a_date", [a_date] )

Thanks. 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors