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
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
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