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
Janaya
Regular Visitor

Power BI Previous Row based on criteria (condtion)

Dear Power BI community:

I would really appreciate if you could help me out with the following issue.

I need to know how long it takes the student to complete a level

 

Janaya_2-1628342670538.pngValues ​​in green are expected

 

Thanks in advance!

 

 

 

2 ACCEPTED SOLUTIONS
TomMartens
Super User
Super User

Hey @Janaya ,

 

I'm sure you can adapt this article The previous value - Mincing Data - Gain Insight from Data (minceddata.info) to your needs.

I'm wondering why the previous log of the 31st of January 2021, is 23rd of November and not the 24th of December 2021. it seems there is a rule that can be applied as a similar pattern appears on 31st of May 2021.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

v-angzheng-msft
Community Support
Community Support

Hi, @Janaya 

 

Create 4 measures like below to do this:

 

1. Levels Completed column work or not

_isTrue = 
var _1=IF(MAX('Table'[Levels Completed])>0,1,BLANK())
var _r=IF(HASONEVALUE('Table'[Levels Completed]),_1,BLANK())
return _r

2.Previous login date

_Previous login = 
var _table=FILTER(ALLEXCEPT('Table','Table'[Student]),'Table'[Last Login]<MAX('Table'[Last Login]))
var _last=CALCULATE(LASTNONBLANK('Table'[Last Login],[_isTrue]),_table)
var _first=CALCULATE(FIRSTNONBLANK('Table'[Last Login],MIN('Table'[Levels Completed])),_table)
var _Pre=IF(_last=BLANK(),_first,_last)
var _ifTrue=IF([_isTrue]=1,_Pre)
return _ifTrue

3. Datediff

_Diff = 
var _diff=DATEDIFF([_Previous login],MAX('Table'[Last Login]),DAY)
var _if=
    IF(
    HASONEVALUE('Table'[Last Login]),
    _diff,
    AVERAGEX(ADDCOLUMNS(SUMMARIZE(ALLSELECTED('Table'),'Table'[Last Login],"pre",[_Previous login]),"diff",DATEDIFF([pre],[Last Login],DAY)),[diff])
    )
return _if

4. average of datediff

_average = 
var _t=SUMMARIZE('Table','Table'[Student],"diff",[_Diff])
var _result=AVERAGEX(_t,[diff])
return _result

Then to create a card visual to show the average of student's datadiff.

 

Result:

vangzhengmsft_0-1628570827095.png

Please refer to the attachment below for details

 

 

Hope this helps.

 

Best Regards,
Community Support Team _ Zeon Zheng
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-angzheng-msft
Community Support
Community Support

Hi, @Janaya 

 

Create 4 measures like below to do this:

 

1. Levels Completed column work or not

_isTrue = 
var _1=IF(MAX('Table'[Levels Completed])>0,1,BLANK())
var _r=IF(HASONEVALUE('Table'[Levels Completed]),_1,BLANK())
return _r

2.Previous login date

_Previous login = 
var _table=FILTER(ALLEXCEPT('Table','Table'[Student]),'Table'[Last Login]<MAX('Table'[Last Login]))
var _last=CALCULATE(LASTNONBLANK('Table'[Last Login],[_isTrue]),_table)
var _first=CALCULATE(FIRSTNONBLANK('Table'[Last Login],MIN('Table'[Levels Completed])),_table)
var _Pre=IF(_last=BLANK(),_first,_last)
var _ifTrue=IF([_isTrue]=1,_Pre)
return _ifTrue

3. Datediff

_Diff = 
var _diff=DATEDIFF([_Previous login],MAX('Table'[Last Login]),DAY)
var _if=
    IF(
    HASONEVALUE('Table'[Last Login]),
    _diff,
    AVERAGEX(ADDCOLUMNS(SUMMARIZE(ALLSELECTED('Table'),'Table'[Last Login],"pre",[_Previous login]),"diff",DATEDIFF([pre],[Last Login],DAY)),[diff])
    )
return _if

4. average of datediff

_average = 
var _t=SUMMARIZE('Table','Table'[Student],"diff",[_Diff])
var _result=AVERAGEX(_t,[diff])
return _result

Then to create a card visual to show the average of student's datadiff.

 

Result:

vangzhengmsft_0-1628570827095.png

Please refer to the attachment below for details

 

 

Hope this helps.

 

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

TomMartens
Super User
Super User

Hey @Janaya ,

 

I'm sure you can adapt this article The previous value - Mincing Data - Gain Insight from Data (minceddata.info) to your needs.

I'm wondering why the previous log of the 31st of January 2021, is 23rd of November and not the 24th of December 2021. it seems there is a rule that can be applied as a similar pattern appears on 31st of May 2021.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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.