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
sarath_chandra
Helper III
Helper III

DAX HELP

HI , in my dataset ,im having setup columns S1,S2,S3,S4,...upto S12.and date column - first day of every month (1/1/2018 to 12/1/2022) and field values . I need previous row difference of each rows .but first row of each setup should be null or zero (it should not take difference of previous set ups) for example s2 should not take the field values of s1. so that particular row should be zero or null. and in difference i have to use ABS dax function to avoid negative sign in output column.

kindly see the data set.please help me out. vry thankfull for your help

sarath_chandra_0-1671114811981.png

help me plzzzz 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @sarath_chandra 

try to add a column with this:

Output2 =
VAR _setup = TableName[SETUP]
VAR _date = TableName[Date]
VAR _value =
MINX(
    FILTER(
        TableName,
        TableName[SETUP]= _setup
            &&VALUE(FORMAT(TableName[Date], "YYYYMM")) = VALUE(FORMAT(TableName[Date], "YYYYMM"))-1
    ),
TableName[Value]
)
RETURN
IF(TableName[Date]<>DATE(2018,1,1), ABS(TableName[OUTPUT] - _value),0)
 
I tried and it worked like this:
FreemanZ_0-1671116667812.png

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @sarath_chandra 

please try

Difference =
VAR CurrentDate = TableName[Date]
VAR CurrentValue = TableName[Value]
VAR CurrentSetupTable =
CALCULATETABLE ( TableName, ALLEXCEPT ( TableName, TableName[Setup] ) )
VAR PreviousRecords =
FILTER ( CurrentSetupTable, TableName[Date] < CurrentDate )
VAR PreviousRecord =
TOPN ( 1, PreviousRecords, TableName[Date] )
VAR PreviousValue =
COALESCE ( MAXX ( PreviousRecord, TableName[Value] ), CurrentDate )
RETURN
ABS ( CurrentDate - PreviousValue )

FreemanZ
Super User
Super User

hi @sarath_chandra 

try to add a column with this:

Output2 =
VAR _setup = TableName[SETUP]
VAR _date = TableName[Date]
VAR _value =
MINX(
    FILTER(
        TableName,
        TableName[SETUP]= _setup
            &&VALUE(FORMAT(TableName[Date], "YYYYMM")) = VALUE(FORMAT(TableName[Date], "YYYYMM"))-1
    ),
TableName[Value]
)
RETURN
IF(TableName[Date]<>DATE(2018,1,1), ABS(TableName[OUTPUT] - _value),0)
 
I tried and it worked like this:
FreemanZ_0-1671116667812.png
sarath_chandra
Helper III
Helper III

@FreemanZ @amitchandak @tamerj1 plz help me out from this

sarath_chandra
Helper III
Helper III

plz help @v-xinruzhu-msft @v-jianboli-msft .very thank ful 

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.

Top Solution Authors