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
aktripathi2506
Helper IV
Helper IV

Calculating measure

Hi,

 

WeekItemCount of Itemavg sale for that item
112146133
1122157
1123654
11241296
11252666
112611114
112753135
1128575
11295110
113013101

 

Raw data is something like this:

item 121 came 46 times and each time and its average sale price among 46 records was 133

item 122 came 1 time and its avg sale price was 57

item 123 came 6 times in the raw data and it was having avg sale 54 for all 6 records

and so on

There are several weeks too, I will be using week as a slicer.

Now what I am looking for is - to write a measure which can add the average of these items

for example 941 in this case

so when I select week 1 from slicer , I get the total item counts and sum of there avg.

 

my final desired output is: 178/941

This is what I am looking for.

 

I will be thankful to any help in this direction.

Thanks

4 REPLIES 4
GilbertQ
Super User
Super User

Hi @aktripathi2506,

 

I would suggest if possible to always look at creating measures before storing the data in each column. Reason being is that if you want to the slice your data with another field, or possibly just get the average for each week, and remove the items, using the column method will mean that you have to create a new column. Which takes time, is not efficient and can cause performance problems in certain instances.

 

I solved your issue by creating the following measures:

 

Counts = SUM('Table1'[Count of Item]) 
Avgs = SUM('Table1'[avg sale for that item])
Output = DIVIDE([Counts],[Avgs]) - Formatted as %

And this was the output, as you can see for the Table total it is the expected 18.92%, as well as you can have other visuals.Power BI - Can Delete.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

hi @GilbertQ 

 

I agreed with your approach somehwat but sometime it is not possible that you can create the data at source level, so it depends on the situation.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k

 

That is true, but you can always edit the data in the Query Editor before you bring it into your Power BI Model.

 

In doing it in this way, your data at source is not modified, but rather you make the changes in the Query Editor which is part of Power BI Desktop.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

parry2k
Super User
Super User

Add new column in your table and o get sum of the average, something like this:

 

my average column = 
var myItem = myTable[Item]
var myCount =  CALCULATE(COUNT(myTable[Item]), FILTER(ALL(myTable),myTable[Item] = myItem))
var mySum = CALCULATE(SUM(myTable[Sale]), FILTER(ALL(myTable),myTable[Item] = myItem))
return DIVIDE(mySum,myCount,0)

try this and see if this works. We would have done it in few lines but try to be more detailed.

 

we can add another column for count as well.

 

Thanks,

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.