cancel
Showing results 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.

Frequent Visitor

Can you do it with measures - Compare 2 results by 2 segments on 1 table

Hello,

I would like to know if it is possible to compare 2 values based on 2 different segments, but both segments are based on the same table.

Let me explain.

I have a simple model, with 2 tables in a 1 to * relationship (dim to fact) :

- Dim1, with information on vehicules (VehiculeNumber, VehiculeSeries)

- Faits1, with vehicule performances (VehiculeNumber, Litres, Km...)

Let's say, I would like to be able to compare performances between specific Series.

I want to be able to select a "reference Series" and a "compare with Series", so I add 2 segments, with the same column, but I deactivate interactions between them so I can view the entire series.

I need to add a measure that would calculate the sum of Litres from one segment - the sum of Litres from the other segment.

I can then add this measure to a single card visual for example.

To put it "simply" :

- Value1 = Sum of Litres from Segment1

- Value2 = Sum of Litres from Segment2

- Variation = Value1 - Value2

Problem is, since Segment1 and Segment2 are based on the same column (Dim1[Series]), any way I tried was unsuccessful.

In image :

I know of a way to get what i want, by just adding a second Dim table similar to the first one, and then just using Series from both Dim tables into different segments. But this method seems terrible when your model gets bigger, as I would need to duplicate certain tables for this sole purpose.

I thought of using ALL, ALLEXCEPT, or ALLSELECTED, but it doesn't seem to work. I have also tried adding a second, identical "Series" column in the Dim1 table, and changed the segments accordingly, but still no work around.

So, does anyone know if it is possible to do this with DAX and measures ? Or do I really need to have different tables ?

1 ACCEPTED SOLUTION
Super User

You would need to have 2 tables. You could create the second one like

``Series 2 = ALLNOBLANKROW( DIM_1[Series] )``

Don't create a relationship from this table to any others, just use it in your slicer and then you can create a measure like

``````Variation =
VAR Val1 =
SUM ( Faits_1[Litres] )
VAR Val2 =
CALCULATE (
SUM ( Faits_1[Litres] ),
TREATAS ( VALUES ( Series2[Series] ), DIM_1[Series] )
)
RETURN
Val1 - Val2
``````
2 REPLIES 2
Super User

You would need to have 2 tables. You could create the second one like

``Series 2 = ALLNOBLANKROW( DIM_1[Series] )``

Don't create a relationship from this table to any others, just use it in your slicer and then you can create a measure like

``````Variation =
VAR Val1 =
SUM ( Faits_1[Litres] )
VAR Val2 =
CALCULATE (
SUM ( Faits_1[Litres] ),
TREATAS ( VALUES ( Series2[Series] ), DIM_1[Series] )
)
RETURN
Val1 - Val2
``````
Frequent Visitor

Okay, thank you, this works great. Too bad we can't do this we just one table, but still cool to be able to have this option.

Announcements

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

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors