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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
only_me321
Frequent Visitor

create a column that is the difference of adjacent variables.

I want to create a column that is the difference of adjacent variables.

 

 Ex. Q1 = Sup_group 2-2 = 0  (Sup_group of Q1 - Sup_group of Q1)

      Q2 = Sup_group 2-3 = -1 (Sup_group of Q1 - Sup_group of Q2)

      Q3 = Sup_group 3-4 = -1 (Sup_group of Q2 - Sup_group of Q3)

      Q4 = Sup_group 4-2 = -1 (Sup_group of Q3 - Sup_group of Q4)

 

result example.....

only_me321_0-1675075445896.png

 

sample data....

only_me321_1-1675075899243.png

 

help me please 😂

thank you,

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @only_me321 
Please refer to attached sample file with the solution

1.png

Result = 
VAR CurrentQuarter = 'Table'[Quarter]
VAR CurrentSupGroup = 'Table'[Sup_group]
VAR GroupProvinceTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[group], 'Table'[province] ) )
VAR TableBefore = FILTER ( GroupProvinceTable, 'Table'[Quarter] < CurrentQuarter )
VAR PreviousRecord = TOPN ( 1, TableBefore, 'Table'[Quarter] )
VAR PreviousSupGroup = COALESCE ( MAXX ( PreviousRecord, 'Table'[Sup_group] ), CurrentSupGroup )
RETURN
    PreviousSupGroup - CurrentSupGroup

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @only_me321 
Please refer to attached sample file with the solution

1.png

Result = 
VAR CurrentQuarter = 'Table'[Quarter]
VAR CurrentSupGroup = 'Table'[Sup_group]
VAR GroupProvinceTable = CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[group], 'Table'[province] ) )
VAR TableBefore = FILTER ( GroupProvinceTable, 'Table'[Quarter] < CurrentQuarter )
VAR PreviousRecord = TOPN ( 1, TableBefore, 'Table'[Quarter] )
VAR PreviousSupGroup = COALESCE ( MAXX ( PreviousRecord, 'Table'[Sup_group] ), CurrentSupGroup )
RETURN
    PreviousSupGroup - CurrentSupGroup

Hi @tamerj1 ,

      Thank you for the DAX. It helped me to pass well. 🙏🙏🙏

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.