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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Bruin87
Frequent Visitor

Filter Context - Card Visual

Hi, 

 

I have a measure (data model: https://community.powerbi.com/t5/Desktop/Semi-Additive-Calculations-Total-Values-wrong/m-p/1824181#M...)

 

Balance Closing =
VAR MaxDate = MAX('Date'[Date])
VAR MaxDates =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(FactBankBalances; FactBankBalances[IBAN]);
"@MaxDate"; CALCULATE(MAX(FactBankBalances[DateKey]))
);
'Date'[Date] <= MaxDate
)
VAR MaxDatesWithLineage =
TREATAS(MaxDates; FactBankBalances[IBAN]; 'Date'[Date])
VAR BalanceClosing = CALCULATE(SUM(FactBankBalances[Kontostand_Euro]); MaxDatesWithLineage)
VAR Result = CALCULATE(
DIVIDE(BalanceClosing;
SELECTEDVALUE(ReportNumberFormat[SelectedDivision]);
1)
)
Return
Result
................................
 
I am trying to show a card visual with this measure for a certain account. However, I am not able to filter the card visual by the account name. I realized that a filter (applied on "all sites" on the date) keeps me from filtering that account, as their values are reported for a date before the selected time frame. Rather than being able to filter a certain account I receive the total of all accounts based on the filter context.
How do i have to change the above mentioned measure so that filtering by FactBankBalances[IBAN] would be possible despite the date filter?
 
Thanks in advance!
Marc
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Bruin87 

According to your description and DAX formula, it seems that the problem exists in the TREATAS() function you used because in this condition, your column FactBankBalances[IBAN] is always filtered by the selected value of ‘Date’[Date].

Therefore, I think you can try to find a way to avoid using the TREATAS() function and use other functions to replace it.

v-robertq-msft_0-1620358068772.png

 

You can try to transform the DAX formulas I circled with the DAX below:

VAR BalanceClosing =
CALCULATE (
    SUM ( FactBankBalances[Kontostand_Euro] ),
    FILTER (
        ALLSELECTED ( FactBankBalances ),
        [IBAN] IN SELECTCOLUMNS ( MaxDates, "1", [@MaxDate] )
    )
)

More info about the TREATAS() function

 

If you still have a problem, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

View solution in original post

2 REPLIES 2
v-robertq-msft
Community Support
Community Support

Hi, @Bruin87 

According to your description and DAX formula, it seems that the problem exists in the TREATAS() function you used because in this condition, your column FactBankBalances[IBAN] is always filtered by the selected value of ‘Date’[Date].

Therefore, I think you can try to find a way to avoid using the TREATAS() function and use other functions to replace it.

v-robertq-msft_0-1620358068772.png

 

You can try to transform the DAX formulas I circled with the DAX below:

VAR BalanceClosing =
CALCULATE (
    SUM ( FactBankBalances[Kontostand_Euro] ),
    FILTER (
        ALLSELECTED ( FactBankBalances ),
        [IBAN] IN SELECTCOLUMNS ( MaxDates, "1", [@MaxDate] )
    )
)

More info about the TREATAS() function

 

If you still have a problem, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Hi @v-robertq-msft , 

thank you for your solution!

I tried to implement it, however, i receive an error message :

 

Error Message:
MdxScript(Model) (36, 35) Calculation error in measure 'DAX Measures'[Balance Closing]: Function 'CONTAINSROW' does not support comparing values of type Date with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values.

 

Is it comparing the account name (IBAN) with the date?

 

best regards

marc

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors