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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
BenediktW
Advocate I
Advocate I

Inherit Values from previous rows

Dear Community,

 

I am facing an issue regarding an inheriting logic. I have a table in my canvas environment (example attached with the key columns), which contains certain subcategories. Those are having an descending index, which will start new for every subcategory. Additionally, I have one value column, which includes for every first row of an subcategory (highest index) an 0 or 1 value. 

With the calculation I want to fill in a new column for every row in the respective subcategory this "first row value". 

 

One special case is, that in the column inherit flag the indentificator "MSCOP" can occur, which turns over the inherting value, as it was previously 0 then its now 1 and the other way round. 

 

Summarization: I want to have an inheriting logic of values (0 or 1), which is firstly just inheriting the value from the previous row. When the indetificators "First row" or "MSCOP" occur, a re-evalution of the to-inherit value should happen. 

 

I tried with some code attached below, but wasnt successfull so far.

 

Thank you very much

 

 

 

VAR CurrentSubcategory = MyTable[Subcategory]
VAR CurrentValue = MyTable[First Row Value]
VAR InheritFlag = MyTable[Inherit_Flag]
VAR CurrentRow = MyTable[Index.1]

VAR InheritedValue =
    CALCULATE(
        MAXX(
            FILTER(
                ALL(MyTable),
                MyTable[Subcategory]] = CurrentSubcategory
                && MyTable[First Row Value] <> BLANK()
                && MyTable[Index.1] < CurrentRow
            ),
            MyTable[First Row Value]
        ),
        ALLEXCEPT(MyTablet, MyTable[Subcategory]])
    )

VAR NewSubcategory =
    NOT (
        MyTable[Subcategory]] = CALCULATE(
            VALUES(MyTable[Subcategory]]),
            MyTable[Index.1] = CurrentRow
        )
    )

RETURN
    IF(
        OR(
            ISBLANK(CurrentValue),
            InheritFlag = "MSCOP"
        ) || NewSubcategory,
        InheritedValue + IF(InheritFlag = "MSCOP", -1, 0),
        BLANK()
    )

 

 

 

 

Subcategory columnIndex.1First Row valueInherit_FlagWished Result
Subkategory  150First Row0
Subkategory 14  0
Subkategory 13 MSCOP1
Subkategory 12  1
Subkategory 11  1
Subkategory 251First Row1
Subkategory 24  1
Subkategory 23  1
Subkategory 22  1
Subkategory 21  1
Subkategory 350First Row0
Subkategory 34  0
Subkategory 33 MSCOP1
Subkategory 32  1
Subkategory 31  

1

1 ACCEPTED SOLUTION

"Subkategory 4" on the screenshot below sounds like the case you described, but it shows the expected values. 

 

Can you share a sequence where it breaks?

 

barritown_0-1704912705430.png

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

View solution in original post

5 REPLIES 5
barritown
Super User
Super User

Hi @BenediktW,

If "MSCOP" can appear only once, you can try such a calculated column:

barritown_0-1704898374630.png

In plain text:

Result = 
VAR CurrentSubcategory = [Subcategory column]
VAR CurrentIndex = [Index.1]
VAR InitialValue = MINX ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory ), [First Row value] )
VAR FinalValue = ABS ( COUNTROWS ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory && [Index.1] >= CurrentIndex && [Inherit_Flag] = "MSCOP" ) ) - InitialValue )
RETURN FinalValue

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Hi,

 

thank you very much already! That is working better than my approaches so far. Unfortunately, it can happen that the "MSCOP" Identifikator shows up multiple times per Subkategory. 

Okay, try this modification then:

Result = 
VAR CurrentSubcategory = [Subcategory column]
VAR CurrentIndex = [Index.1]
VAR InitialValue = MINX ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory ), [First Row value] )
VAR FinalValue = ABS ( MOD ( COUNTROWS ( FILTER ( MyTable, [Subcategory column] = CurrentSubcategory && [Index.1] >= CurrentIndex && [Inherit_Flag] = "MSCOP" ) ), 2 ) - InitialValue )
RETURN FinalValue

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Works well, but when the first row value is 1 and there is an "MSCOP" Identificator. The following rows after that are staying one. 

"Subkategory 4" on the screenshot below sounds like the case you described, but it shows the expected values. 

 

Can you share a sequence where it breaks?

 

barritown_0-1704912705430.png

 

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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