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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Kalibur
Frequent Visitor

Have calculations only work in the filtered context

I hope this is a simple question and I don't know what to actually google. This is just a sample of what I actually want to do but this functionality applies to so many things i want to do. 

 

I have a table that has 2 columns. [TestName, Log Time]

 

Every test ran for a different period of time and my goal is to calculate how much time is left in the test at any specific log time. I'm making a line graph over time. TimeRemaining vs LogTime.

 

The formula for this is simple TimeRemaining = Max(LogTime) - LogTime.

 

The issue that Max(LogTime) for the data set is larger than Max(LogTime) for any particularly TestName that i'm filtering to. When i filter my line graph to an individual test name how do I ensure that the filter applies to the TimeRemaining calculation? As you can see in the picture below the TimeRemaining is not 0 at the end of this test since the context of my filter is not correctly applied to the calculation.  

Kalibur_0-1709675158717.png

 



1 ACCEPTED SOLUTION

hi @v-kaiyue-msft 

 

I wasn't aware of the AllExcept function. That seems useful. Unfortunately your suggestion didn't solve the problem. It wants me to aggregate the second log time. On the other hand the Max(LogTime) is returning the max log time based on my testname filter. 

 

 

Kalibur_0-1709731970029.png

 


"A single value for column "Log Time" in table cannot be determined. Ths can happen when a measure formula refers to a column that contains many values without specifying an aggregation....." 

 

Update: you got me really close. I ended up getting it to work with this equation. 

TimeRemaining =
VAR MaxLogTimeForTest = CALCULATE(MAX([Log Time]), ALLEXCEPT(combined_output, combined_output[Test Name]))
RETURN
MaxLogTimeForTest - [Log Time]

View solution in original post

2 REPLIES 2
v-kaiyue-msft
Community Support
Community Support

Hi @Kalibur ,

 

You can try adjusting the expression to:

TimeRemaining=
CALCULATE(
MAX('Table'[Log Time]) - 'Table'[Log Time],
ALLEXCEPT('Table', 'Table'[TestName])
)


The ALLEXCEPT function removes all contextual filters from the table except those that have been applied to the specified column. More details can be found in the documentation: ALLEXCEPT function (DAX) - DAX | Microsoft Learn.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

hi @v-kaiyue-msft 

 

I wasn't aware of the AllExcept function. That seems useful. Unfortunately your suggestion didn't solve the problem. It wants me to aggregate the second log time. On the other hand the Max(LogTime) is returning the max log time based on my testname filter. 

 

 

Kalibur_0-1709731970029.png

 


"A single value for column "Log Time" in table cannot be determined. Ths can happen when a measure formula refers to a column that contains many values without specifying an aggregation....." 

 

Update: you got me really close. I ended up getting it to work with this equation. 

TimeRemaining =
VAR MaxLogTimeForTest = CALCULATE(MAX([Log Time]), ALLEXCEPT(combined_output, combined_output[Test Name]))
RETURN
MaxLogTimeForTest - [Log Time]

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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