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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Flag Differences in Row vs Previous Row (based on Date, Site, and Person)

Hello,

I have a table set up like below.
Linked to a Site Key and a Date Dimension.

My goal is to come up with a formula for the "Change Indicator" column (currently a calculated column), where it will show a "1" if there's a change in any of the numbers for the SiteID+UniqueID2 compared to the month previous:

DateSiteIDUniqueID2NameNum1Num2Num3Num4Num5Num6TotalChange Indicator
7/1/2020A3333Person30.300.070.050.170.060.200.850
7/1/2020B3333Person30.100.020.000.030.000.000.150
8/1/2020A3333Person30.350.070.000.170.060.200.851
8/1/2020B3333Person30.100.020.000.030.000.000.150
9/1/2020A3333Person30.350.070.000.170.060.200.850
9/1/2020B3333Person30.100.020.000.030.000.000.150
10/1/2020A3333Person30.350.070.000.170.060.200.850
10/1/2020B3333Person30.100.000.000.040.000.010.151
11/1/2020A3333Person30.400.070.000.170.060.200.901
11/1/2020B3333Person30.050.000.000.040.000.010.101


I started with just trying to get the difference based on "Num1" and once I had that right, I was going to work through Num2, Num3, etc. This is what I've tried:
Change Indicator = if(isblank(sumx(Table,Filter(Table,Table[UniqueID2]=Earlier(Table[UniqueID2]) && Table[Num1]<>Earlier(Table[Num1])))),1,0)
Error message: multiple columns cannot be converted to scalar values

Change Indicator = Table[Num1] - Lookupvalue(Table[Num1],Table[UniqueID2],[UniqueID2],Table[SiteID],[SiteID],Table[Date], DateAdd(Table[Date],-1,month))
This doesn't give me any error message to work off of, all column cells come back #ERROR.

Unfortunately I cannot provide any data files, etc, which I know is preferred.

If anyone would just point me in a general direction (links, examples, ideas), I would appreciate it.
I was reading about using index colums. Would that help at all? I didn't think I needed them since it's all based on the Date column.

TYIA.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

None of the replies I received worked, but this is what I figured out:
 To compare to previous month - use Measure:
    Change Indicator = if(min(Table[Date]<>Date(2020,07,01),
                                       If(Calculate(sum(Table[Num1]),PreviousMonth(Table[Date])) <> sum(Table[num1],
                                       1,0)


After I got this part working, I was asked to compare each month to the first month of the fiscal year (7/1/2020) rather than to the previous month. The only way I could get this to work was as a calculated column:

   Change Indicator = 
         Var _FirstDayFP = If(Table[FiscalPeriod]=2021, Date(2020,07,01),
                                      If(Table[FiscalPeriod]=2022, Date(2021,07,01),0))
         Return
         If(
           Table[Num1]
           <>
           Calculate(sum(Table[Num1]),
                           filter(Table,Table[Date]=_FirstDayFP),
                           filter(Table,Table[UniqueID2]=Earlier(Table[UniqueID2])),
                           filter(Table,Table[SiteID]=Earlier(Table[SiteID])),
                           filter(Table,Table[FiscalPeriod]=Earlier(Table[FiscalPeriod]))),
            1, 0)
Appreciate any feedback/comments/thoughts.
Hope this helps someone else.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

None of the replies I received worked, but this is what I figured out:
 To compare to previous month - use Measure:
    Change Indicator = if(min(Table[Date]<>Date(2020,07,01),
                                       If(Calculate(sum(Table[Num1]),PreviousMonth(Table[Date])) <> sum(Table[num1],
                                       1,0)


After I got this part working, I was asked to compare each month to the first month of the fiscal year (7/1/2020) rather than to the previous month. The only way I could get this to work was as a calculated column:

   Change Indicator = 
         Var _FirstDayFP = If(Table[FiscalPeriod]=2021, Date(2020,07,01),
                                      If(Table[FiscalPeriod]=2022, Date(2021,07,01),0))
         Return
         If(
           Table[Num1]
           <>
           Calculate(sum(Table[Num1]),
                           filter(Table,Table[Date]=_FirstDayFP),
                           filter(Table,Table[UniqueID2]=Earlier(Table[UniqueID2])),
                           filter(Table,Table[SiteID]=Earlier(Table[SiteID])),
                           filter(Table,Table[FiscalPeriod]=Earlier(Table[FiscalPeriod]))),
            1, 0)
Appreciate any feedback/comments/thoughts.
Hope this helps someone else.

o_zavalnyuk
Regular Visitor

here is the full DAX code

Change Indicator Calc = 
var num1 = 'Table'[Num1]
var num2 = 'Table'[Num2]
var num3 = 'Table'[Num3]
var num4 = 'Table'[Num4]
var num5 = 'Table'[Num5]
var num6 = 'Table'[Num6]
var dateT = 'Table'[Date]
var siteID = 'Table'[SiteID]
var filtertable = 
     FILTER(
        'Table';
        MONTH('Table'[Date]) = MONTH(dateT)-1
        && 'Table'[SiteID] = siteID
    )
var calcNum1 = 
    CALCULATE(
        COUNT('Table'[SiteID]);
        FILTER(
            filtertable;
            'Table'[Num1] <> num1
            || 'Table'[Num2] <> num2
            || 'Table'[Num3] <> num3
            || 'Table'[Num4] <> num4
            || 'Table'[Num5] <> num5
            || 'Table'[Num6] <> num6

        )
    )
var result = 
    SWITCH(
        TRUE();
        ISBLANK(calcNum1); 0;
        NOT(ISBLANK(calcNum1)); 1
    )
return result
Ashish_Mathur
Super User
Super User

Hi,

Can you live with this?  You may download my PBI file from here.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

your file has num1, num2, num3 each in their own row
my powerbi table is set up exactly as in the question - num1, num2, num3 are columns within the same row, so i have to compare row to row, not within a column.
is there a way to use indexing or some other technique to compare row to row?

Hi,

I have applied transformations on your data using the Query Editor.  Please study my solution carefully.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
o_zavalnyuk
Regular Visitor

Change Indicator Calc = 
var num1 = 'Таблица (2)'[Num1]
var num2 = 'Таблица (2)'[Num2]
var dateT = 'Таблица (2)'[Date]
var siteID = 'Таблица (2)'[SiteID]
var calcNum1 = 
CALCULATE(
    SUM('Таблица (2)'[Num1]);
    FILTER(
        'Таблица (2)';
        'Таблица (2)'[Num1] <> num1 
        && MONTH('Таблица (2)'[Date]) = MONTH(dateT)-1
        && 'Таблица (2)'[SiteID] = siteID
    )
)
var p2 = 
SWITCH(
    TRUE();
    ISBLANK(calcNum1); 0;
    NOT(ISBLANK(calcNum1)); 1
)
return p2

Это рабочий пример только с 1 колонкой "num1". Теперь ваша задача состоит в том, чтобы добавить другие столбцы в код, чтобы проверить значения

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors