Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.
I am trying to get the TRUE/FALSE value of the previous row. I have read to be able to do this for a row that isn't a number I need to use FIRSTNONBLANK with a 1 as the expression. However, for some reason this works for a bit then just wants to stick to a single value.
I have used the following DAX to get to this:
=
CALCULATE
(
FIRSTNONBLANK
(
'Sample Data'[Oil Changed],1
),
FILTER
(
'Sample Data',
'Sample Data'[Sample Date] < EARLIER
(
'Sample Data'[Sample Date]
)
&& 'Sample Data'[Unit Number] = EARLIER
(
'Sample Data'[Unit Number]
)
)
)
This is the output, plus what I actually want in the end column.
Does anyone know how I can do this? Power BI example file below.
Just as a side rant, there really needs to be a better way of doing something simple like this. In Excel, it is literally "=[cell you want to reference]" in a table and it's done for the whole column. In DAX this is several lines of code...
Solved! Go to Solution.
Hi @justlogmein,
How about this?
Oil Changed for Previous Row 2 =
VAR PreDate_ =
CALCULATE (
MAX ( 'Sample Data'[Sample Date] ),
FILTER (
'Sample Data',
'Sample Data'[Sample Date] < EARLIER ( 'Sample Data'[Sample Date] )
&& 'Sample Data'[Unit Number] = EARLIER ( 'Sample Data'[Unit Number] )
)
)
VAR PreOilChanged_ =
CALCULATE (
FIRSTNONBLANK ( 'Sample Data'[Oil Changed], 1 ),
FILTER (
'Sample Data',
'Sample Data'[Sample Date] = PreDate_
&& 'Sample Data'[Unit Number] = EARLIER ( 'Sample Data'[Unit Number] )
)
)
RETURN
PreOilChanged_
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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! |
Thank you for this, however when I try I am not getting the expected results. I am getting 1's and 0's and the pattern doesn't seem to line up with the Oil Changed column. Any ideas?
Hi @justlogmein,
How about this?
Oil Changed for Previous Row 2 =
VAR PreDate_ =
CALCULATE (
MAX ( 'Sample Data'[Sample Date] ),
FILTER (
'Sample Data',
'Sample Data'[Sample Date] < EARLIER ( 'Sample Data'[Sample Date] )
&& 'Sample Data'[Unit Number] = EARLIER ( 'Sample Data'[Unit Number] )
)
)
VAR PreOilChanged_ =
CALCULATE (
FIRSTNONBLANK ( 'Sample Data'[Oil Changed], 1 ),
FILTER (
'Sample Data',
'Sample Data'[Sample Date] = PreDate_
&& 'Sample Data'[Unit Number] = EARLIER ( 'Sample Data'[Unit Number] )
)
)
RETURN
PreOilChanged_
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Excel is a spreadsheet and has a named cell reference. This means every datapoint has its own address. This is very useful, but comes at a cost. Try adding a million rows of data and writing a formula in each row. Power BI is not a spreadsheet, it is a column store reporting database. It is optimised for fast and efficient aggregations, calculations and data storage. But that comes at a cost. There is no cell reference and no referential "order" in the data itself, hence this particular problem is difficult to solve in PBI.
Depending on the problem, you may be better off loading the value from the "previous row" using Power Query and loading it into the final loaded table in PBI. I show how to do this in my video here.
https://youtu.be/xN2IRXQ2CvI
This may add preprocessing time, but it's often a better way to solve the problem.
Check out the November 2023 Power BI update to learn about new features.
Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.
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!