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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
TejasShah
Helper I
Helper I

Add a measure in Visual Table to add column

I have 2 tables as below :

 

TejasShah_1-1705484663083.png

 

 

TejasShah_0-1705484516422.png

where I have calculated Avg = 

CALCULATE(AVERAGE(Consumption[Consumption]), FILTER(Consumption, (Meter_Consumption_Table[Year] = YEAR(NOW())) && Consumption[ID] = Master_Meter[ID]))
 
I am creating a Visual Table on the desktop appln. where in I am able to get below results:
 
TejasShah_2-1705484721368.png

 

But, I also need another column which would give me Difference of Consumption and Average:

 

TejasShah_3-1705484784948.png

 

I only need the Red values, green values can or cannot be included based on requirement. 

 

I tried doing this using the below formula, but it takes the Sum of all the Average values in the column average and compares it with the Consumption details instead of comparing it with individual ID average

 

Difference =
VAR day_consumption = SUM(Consumption[Consumption])
RETURN
IF (day_consumption > SUM(Master_Meter[Average]), day_consumption - SUM(Master_Meter[Average])
 
Can someone please help me with this problem
 
1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

hi, @TejasShah 

 

avg measure 

avg = 
 CALCULATE(
    AVERAGEX( consumption,consumption[consumption]),
    ALLEXCEPT(consumption,consumption[meter name])
)

 

diff measure

diff = 
MIN(consumption[consumption])-[avg]

 

Dangar332_0-1705495213729.png

 

View solution in original post

10 REPLIES 10
Dangar332
Super User
Super User

hi, @TejasShah 

 

avg measure 

avg = 
 CALCULATE(
    AVERAGEX( consumption,consumption[consumption]),
    ALLEXCEPT(consumption,consumption[meter name])
)

 

diff measure

diff = 
MIN(consumption[consumption])-[avg]

 

Dangar332_0-1705495213729.png

 

Hi @Dangar332 ,

 

Thank you so much for the quick response, really appreciated. 

 

I have achieved my solution exactly how I want it to be.

 

Thanks once again.

Sorry to bother you @Dangar332 ,

 

But if I need a filter where in I only need consumption which are above X units (where X is different for individual IDs), can we include the same while calculating the avg ?

 

hi, @TejasShah 

 

clear specification
provide requirment 

means describe specific unit for each id for help

 

hi @Dangar332, Sure, I mean to say for example as per the DAX formula given by you, we are successful in getting avg of all the values for a specific Meter_Name: avg = CALCULATE( AVERAGEX( consumption,consumption[consumption]), ALLEXCEPT(consumption,consumption[meter name]) ) But for instance, if I need to consider only values above 105 for meter_name C for calculating the avg: i.e. instead of 106.5 for "C's" avg, I'll get 109.5 as avg since only 107 and 112 would be considered

hi, @TejasShah 

try below measure 

 

Measure 2 = 
var a = SELECTEDVALUE(consumption[consumption])
RETURN
   
    CALCULATE(
    AVERAGE(consumption[consumption]),
    consumption[consumption]>=a,
   ALLEXCEPT(consumption,consumption[meter name])
    )

 

 

make slicer for consumption 

Dangar332_0-1705518876335.png

 

Hi @Dangar332 

Okay, I am able to get what I need through this as well, just that I have to add a slicer for particular meter name.

Thank you so much for your help. Have a wonderful day!

Hi, @TejasShah 

 

If you want it hard-coded then replace (>=a) here a with your desired value like 105,107

Like below  (>=105)

Vallirajap
Resolver III
Resolver III

Hi @TejasShah 

I tried the above use case based on my understanding; below, I share the screen shot. Is there any query you mentioned to ask?

 

Vallirajap_0-1705488961091.png

 

Did I answer your question?

Mark my post as a solution, this will help others...!

Hit the kudo also,

Thank you

 

Hi @Vallirajap ,

 

You are using the same table for calculating the difference, actually this table which I have is a Visual table on my BI report and not a data table. I suppose we won't be able to use Visual table columns in measure to achieve our difference column

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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