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

AVERAGEX help needed

Hello Experts, looking for some guidance or help in calculating Average Unit rate values based on 2 conditions (ID num, Doc Num). If I had to do it in excel, I can simply use AVERAGEIFS, which I believe can be done using AVERAGEX in DAX. Though I tried hard, I am unable to get the correct output. I would appreciate any help on this. Below is the dataset. I have appended 2 queries in one table with a touchpoint field. I need avg unit rate, and sum of qty for Main lines, from Numbers.

 

Touch PointID NumberDoc NumberUnit RateQtyAvg Unit RateQty Consumed
Main123AA1  17.557
Main123AA1  17.557
Main123AA2  1145
Main124BE2  2612
Main124BD1  1265
Main124BD3  11.5342
Main124BD3  11.5342
Main125DD1  30.523
Main125DD4  2121
Main125DD1  30.523
Main126DD1  3615
Main126DD4  2112
Numbers123AA11245  
Numbers123AA12312  
Numbers123AA21145  
Numbers124BE22612  
Numbers124BD11265  
Numbers124BD31221  
Numbers124BD311321  
Numbers125DD12511  
Numbers125DD42121  
Numbers125DD13612  
Numbers126DD13615  
Numbers126DD42112  

 

 

1 ACCEPTED SOLUTION

@Anonymous

 

Try

 

Avg_Unit_Rate =
IF (
    TableName[Touch Point] = "Main",
    CALCULATE (
        AVERAGE ( TableName[Avg Unit Rate] ),
        ALLEXCEPT ( TableName, TableName[ID Number], TableName[Doc Number] )
    )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @Anonymous,

 

Just ti understand a little better the information to what I can see from the data set the ID number and Doc Number is common with Main lines and Number lines.

 

Why don't you just make a single merged table all the columns setup would look like this:

 

ID NumberDoc NumberUnit RateQtyAvg Unit RateQty Consumed
123AA1124517.557
123AA1231217.557
123AA211451145
124BE226122612
124BD112651265
124BD3122111.5342
124BD31132111.5342
125DD1251130.523
125DD421212121
125DD1361230.523
126DD136153615
126DD421122112

 

Or does this not make sense for your data?

 

Can you please also tell what is the final result you need because based on the dataset you could just do AVERAGE because the measures are context based so using it with different levels of information will make the calculation accordingly.

 

AVERAGEX is used to calculate the average a table using line by line calculation example, you wanted to make the sum of all the Av Unit rate within ID number and of that make the average.

 

But if you can add additional expectations I can help you better.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Also, I need these 2 to be on as calculated columns instead of measures, as I have a few more further columns being calculated depended on the unit rate and qty consumed. 

 

AVERAGEX is used to calculate the average a table using line by line calculation example, you wanted to make the sum of all the Av Unit rate within ID number and of that make the average.

that is exactly what I need.

@Anonymous

 

Try

 

Avg_Unit_Rate =
IF (
    TableName[Touch Point] = "Main",
    CALCULATE (
        AVERAGE ( TableName[Avg Unit Rate] ),
        ALLEXCEPT ( TableName, TableName[ID Number], TableName[Doc Number] )
    )
)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hi @Zubair_Muhammad - thanks a bunch for your response. Would this be a measure or a calculated column ?

hi

It is a calculated column

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Nice!!! I will try and let you know. Thanks again for your help.

Anonymous
Not applicable

hi @MFelix - thanks for your quick response, I appreciate it. I have 2 tables, Numbers and Main. In main table, I just have ID & Doc number, and in Numbers table, I have ID, Doc #, Unit Rate, Qty. Since I have a date column, and I need to relate it to a calendar table, I merged these 2 tables into one with a touchpoint column. Now, I need to pull the Avg Unit Rate and Total Qty consumed for each of the ID & Doc combination, against ID & Doc of Main lines. 

 

Please let me know if its not clear. thanks again.

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.