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

Averaging a columns values with no filter and displaying the result staticly in rows

I have a column with percantage-values. I want to average all unique values from this column and display the static average result at every row! However; When I use different Dax codes that should do this - I get an "average" that alligns with the "gennemsnitCpr" value. The idea is simply to average a column filter free and display the same static value in all the new column's rows.

My query is: 

calculate(AVERAGE('Table'[GennemsnitICpr]),all('Table'[gennemsnitICpr]))
kundetotalcprcvrgennemsnitICpr

Average

NRGi20025420289.50%89.50%

NRGi

20025402089.50%89.50%
NRGi20025434489.50%89.50%
HEF50025423422.50%22.50%
SydFyn60025423490.55%90.55%

 

1 ACCEPTED SOLUTION

No, it should be fine if you've already created a calculated column.

Here I have created the [gennes...] column in the data model the same as you have, then applied the formula that is giving the correct output:

arrakha5.PNG

 

Not sure why this isn't working for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

9 REPLIES 9
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

My first guess is that your [GennemsnitlCpr] field is not a numerical data type.

In Power Query, select this field and change the data type to decimal. Apply to the model, then see if your column works as expected.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hey @BA_Pete 

Nope - Didnt help. 

I found out how to get rid of "NaN". I simply changed my DAX code to: 

CALCULATE(AVERAGE('Table'[gennemsnitICpr),All('Table'[gennemsnitICpr]))
 
However, this output an average that alligns with "gennemsnitICpr" in each row - Which is definitly not what I want. I want a static average to be displayed in a column on all rows

Hi @Anonymous ,

 

Are you able to provide a sample of your data in table format please?

When you reply, you can use this button to add data in table format:

arrakha.PNG

 This makes it much quicker and easier for people to pick up a sample of your data for testing. This, in turn, means your question will be answered quicker.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hey @BA_Pete 

I changed it to the best of my ability 😄

No problem, that's perfect.

 

Make sure that your source data looks like this in Power Query before applying to the model:

arrakha2.PNG

 

Then use the following DAX formula in a new column:

 

Average = 
CALCULATE(
    AVERAGE(aTable[gennemsnitICpr]),
    ALL(aTable)
)

 

 

This gives me the following output (after changing the format to Percentage in the data model side, not Power Query side):

arrakha.PNG

 

 Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hey @BA_Pete 

Hey, Pete. 

How exactly do I express it as you have. Cuz I cant seem to make it appear like your formatting in your table?

Arrakha_1-1596025157640.png

 

Note; (gennemsnitICpr) is actually a division formula. So its value is based on the division of "cpr" / "total". I dont know if this makes a difference in the average calculation ?

@Anonymous 

 

It looks like you're trying to change it in the data model rather than in Power Query.

 

Hit this button to open Power Query, where you can right-click on the column header and go to Change Type to change the DATA TYPE to decimal.

arrakha3.PNG

 

arrakha4.PNG

 

Then, still in Power Query, go to File>Close & Apply. This will push this change back into the data model.

Back in the model, you can then select that column again and change the FORMAT to Percentage.

 

Formats and Data Types are not the same thing.

 

Pete

 



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Anonymous
Not applicable

Hi @BA_Pete 

Ah okay, I see!

Now there is another issue. Im essentially working on data thats coming from my company's live database. The column "gennemsnitICpr" is a column I have created in the data model overview as a division of two database-columns. If I go to Power Query I wont find "gennemsnitICpr". 

 

Does this mean I can only do this to columns coming from a datasource?

No, it should be fine if you've already created a calculated column.

Here I have created the [gennes...] column in the data model the same as you have, then applied the formula that is giving the correct output:

arrakha5.PNG

 

Not sure why this isn't working for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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.

Top Solution Authors