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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Roym
Helper IV
Helper IV

Session result calculation based (including previous result)

I have a table with a long list of assessment results, both the test and review, and based on that I need to calculate the New_Result.

 

What I need to do is determine the New_Result based on the previous sessions. 

 
1. If the test is effective, and the review is also effective -> New result = Effective
2. If test is effective, and review is Ineffective -> New result = Ineffective 
3. If the test is effective, and the review is Open -> New result = the review result from the previous assessment.
(Review is always prefered above the test result)
 

Now I have this working (with some previous help) as shown below. But the only thing that I havn't figgured out yet is that the calculation should also keep the session number in mind. So in the below example it works until ID=4, but ID=5 is not correct anymore because it still followes the logic, but should start over again because the session number is not 1 anymore but 2.

 

I have also the code and Pbix file attached. Hopefully someone can give me some guidance on how to solve this 🙂

 

Capture.PNG

 

Column =
var _previosid=MAXX(filter('Table','Table'[Test]=EARLIER('Table'[Test])&& 'Table'[ID]<EARLIER('Table'[ID])),'Table'[ID])
var _review=CALCULATE(MAX('Table'[Review]),FILTER('Table','Table'[ID]=_previosid))
return
SWITCH(TRUE(),'Table'[Test]="Effective" && 'Table'[Review]="Effective","Effective",
'Table'[Test]="Effective" && 'Table'[Review]="Ineffective","Ineffective",
'Table'[Test]="Effective" && 'Table'[Review]="Open",_review)
 
7 REPLIES 7
Roym
Helper IV
Helper IV

Anyone any idea how to solve this last item, the one missing result in the calculted column? 

CNENFRNL
Community Champion
Community Champion

I'm wondering the use of [Test] column since all values are the same.

CNENFRNL_0-1656507284235.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Not sure what you exactly mean with this? Is there something I need to adjust in the 'test' column?

amitchandak
Super User
Super User

@Roym , I think it should be session in first Var

 

Column =
var _previosid=MAXX(filter('Table','Table'[session]=EARLIER('Table'[session])&& 'Table'[ID]< EARLIER('Table'[ID])),'Table'[ID])
var _review=CALCULATE(MAX('Table'[Review]),FILTER('Table','Table'[ID]=_previosid))
return
SWITCH(TRUE(),'Table'[Test]="Effective" && 'Table'[Review]="Effective","Effective",
'Table'[Test]="Effective" && 'Table'[Review]="Ineffective","Ineffective",
'Table'[Test]="Effective" && 'Table'[Review]="Open",_review)

@amitchandak  Nicee, this (almost) works! Not sure why, but for the first new session (2) it keeps the column empty, any idea how to fix that? The rest is working perfectly now!! Thanks

 

Roym_0-1656506969237.png

 

HI @Roym,

The expression is calculated based on the current session group, so the highlight row can't find out previous records with the same session group to calculate.

For this scenario, it means you need to add a condition to check if the current row is the first row, then you can use the current id to find out the previous id and use it as a condition to calculate.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft Thanks, this makes sense. Can you give any additional guidance on how to implement this? I'm not sure how, thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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