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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
markharoldr
Regular Visitor

Creating Calculated Table With some filtering based on row values

Hello Everyone, 

I want to create a calculated table based from this existing table:

markharoldr_0-1689852866762.png

The aim is to only include rows with items from VersionItem, Change columns where there is a change in value under Change
Example Result:

markharoldr_1-1689852937252.png

Any clues on how to do this? Getting confused for the formula for DAX with this one. 

Regards,

Mark

 

4 REPLIES 4
DoubleJ
Solution Supplier
Solution Supplier

Hi

I did this in 3 steps:
1. In Power Query add an Index row (row is called ID)
2. Add a custom column "HasChanged" in DAX. Check if the value of the "Change" column has switched (compared to the row with closest lower ID). Output is "true" or "false"
3. Create a table using only the rows with "HasChanged" = "true"

Add Index column in PQ (step 1):

DoubleJ_0-1689857826406.png

 

DoubleJ_1-1689857888419.png


Formula for calculated column (step 2):

HasChanged = /*Calculated Column => every row in the table is iterated*/
VAR _ID = Versions[ID]              /*ID of current row*/
VAR _Change = Versions[Change]      /*Change of current row*/
VAR _PrevID =                       /*Get the ID of the previous row*/
MAXX(
    FILTER(
        Versions,
        Versions[ID] < _ID),
    Versions[ID])
VAR _ChangePrevID =                 /*Get Change of previous row*/
MINX(
    FILTER(
        Versions,
        Versions[ID] = _PrevID),
    Versions[Change])

RETURN _Change <> _ChangePrevID     /*Check if "Change" has a different value than in previous row*/  


Formula for calculated table (step 3):

Versions with changes = CALCULATETABLE(Versions,Versions[HasChanged])


I'm sure there are more elegant and compact ways to do this.  Hope this helps anyway.
JJ

Thanks @DoubleJ . It works as expected and I need to sort first the table by Item and Version in power query. Though in a large data set around 100k rows it seems it is taking a while to compute the calculated column.

Appreciated your answer 🙂

 

Regards,

Mark 


how long does it take  to compute the calculated column?

Around 15 minutes for 100k rows

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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