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
Anonymous
Not applicable

DAX compare data from same table

Hi, new to powerbi, still having a play!

 

I have adhoc snapshots of data, all brought into the same table.  This shows three snapshots, but there could be as many as 24 or 36.

 

SS     Prod   Total

100   A   15

100   B   6

100   C   7

101   A   12

101   B   6

101   C   8

102   A   11

102   B   6

102   C   8

 

I want to have a list where I can choose 101, 102, 103 and have a table which shows

     101    102    Var

A  12       11      -1

B   6        6        0

C   8        8        0

 

or

 

     100    102    Var

A  15       11      -4

B   6        6        0

C   7        8        1

 

I've simplied this massively, but basically I want to be able to bring in a colum of information from the data set and compare it side by side.

 

I've created a seperate table which has

SS       Index

100     1

101     2

102     3

104     4

Product_total 1 = CALCULATE(SELECTEDVALUE(PRODUCT[product_name]),filter(SNAPSHOT,SNAPSHOT[Index]=1))
Product_total 2 = CALCULATE(SELECTEDVALUE(PRODUCT[product_name]),filter(SNAPSHOT,SNAPSHOT[Index]=2))
 
Is there any way to make [index]=Slicer_variable?
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can try to use below formula to calculate difference between selected column items:

Measure =
VAR _min =
    MINX ( VALUES ( Table3[SS] ), [SS] )
VAR _max =
    MAXX ( VALUES ( Table3[SS] ), [SS] )
RETURN
    IF (
        HASONEVALUE ( Table3[SS] ),
        CALCULATE ( SUM ( Table3[Total] ), VALUES ( Table3[Prod] ) ),
        IF (
            COUNTROWS ( VALUES ( Table3[SS] ) ) = 2,
            CALCULATE ( SUM ( Table3[Total] ), Table3[SS] = _min )
                - CALCULATE ( SUM ( Table3[Total] ), Table3[SS] = _max )
        )
    )

55.gif

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can try to use below formula to calculate difference between selected column items:

Measure =
VAR _min =
    MINX ( VALUES ( Table3[SS] ), [SS] )
VAR _max =
    MAXX ( VALUES ( Table3[SS] ), [SS] )
RETURN
    IF (
        HASONEVALUE ( Table3[SS] ),
        CALCULATE ( SUM ( Table3[Total] ), VALUES ( Table3[Prod] ) ),
        IF (
            COUNTROWS ( VALUES ( Table3[SS] ) ) = 2,
            CALCULATE ( SUM ( Table3[Total] ), Table3[SS] = _min )
                - CALCULATE ( SUM ( Table3[Total] ), Table3[SS] = _max )
        )
    )

55.gif

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Thanks v-shex-msft, worked a treat!

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.