cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
jhlatinia
New Member

Average between two columns not correct

Hello,

I've been trying to calculate the average of the division of 2 columns in PowerBi Desktop and not receive the right results.

2022-11-21 13_43_31-Lead Gen - Power BI Desktop.png

As you can see the column CTR is returning 0,66% for the first line, when it should be: 0.58%

And it return 0,80 for the second, when it should be 0,83.

My Column CTR is :

CTR = DIVIDE(LinkedInAds[Clicks],LinkedInAds[Impressions],0)
Thank you for your help.
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @jhlatinia ,

 

The result you get is incorrect is because it is the sum of all rows. In other words, they calculate the percentage of each row first and then sum it, which gives a different result than summing and then calculating the percentage.

Please try:

CTR = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Campaign Group Name],
        "CTR",
            DIVIDE (
                CALCULATE (
                    SUM ( 'Table'[Clicks] ),
                    FILTER (
                        'Table',
                        [Campaign Group Name] = EARLIER ( 'Table'[Campaign Group Name] )
                    )
                ),
                CALCULATE (
                    SUM ( 'Table'[Impressions] ),
                    FILTER (
                        'Table',
                        [Campaign Group Name] = EARLIER ( 'Table'[Campaign Group Name] )
                    )
                )
            )
    )
RETURN
    AVERAGEX ( _a, [CTR] )

Final output:

vjianbolimsft_0-1669620580276.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-jianboli-msft
Community Support
Community Support

Hi @jhlatinia ,

 

The result you get is incorrect is because it is the sum of all rows. In other words, they calculate the percentage of each row first and then sum it, which gives a different result than summing and then calculating the percentage.

Please try:

CTR = 
VAR _a =
    SUMMARIZE (
        'Table',
        'Table'[Campaign Group Name],
        "CTR",
            DIVIDE (
                CALCULATE (
                    SUM ( 'Table'[Clicks] ),
                    FILTER (
                        'Table',
                        [Campaign Group Name] = EARLIER ( 'Table'[Campaign Group Name] )
                    )
                ),
                CALCULATE (
                    SUM ( 'Table'[Impressions] ),
                    FILTER (
                        'Table',
                        [Campaign Group Name] = EARLIER ( 'Table'[Campaign Group Name] )
                    )
                )
            )
    )
RETURN
    AVERAGEX ( _a, [CTR] )

Final output:

vjianbolimsft_0-1669620580276.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-jianboli-msft
Community Support
Community Support

Hi @jhlatinia ,

 

What does your Start Date look like? What is the relationship between the date and the value?

Sorry for that the information you have provided is not making the problem clear to me. Can you please share more details to help us clarify your scenario?

Please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

2022-11-23 11_57_08-LinkedInAds - Excel.png

This is the format.

v-jianboli-msft
Community Support
Community Support

Hi @jhlatinia ,

 

Are you trying to calculate the average of the CTR?

Here is my sample:

vjianbolimsft_0-1669106549646.png

Please try:

Measure =
VAR _a =
    SUMMARIZE (
        'LinkedInAds',
        LinkedInAds[Group Name],
        "CTR",
            DIVIDE (
                CALCULATE (
                    SUM ( LinkedInAds[Clicks] ),
                    FILTER ( 'LinkedInAds', [Group Name] = EARLIER ( LinkedInAds[Group Name] ) )
                ),
                CALCULATE (
                    SUM ( LinkedInAds[Impressions] ),
                    FILTER ( 'LinkedInAds', [Group Name] = EARLIER ( LinkedInAds[Group Name] ) )
                )
            )
    )
RETURN
    AVERAGEX ( _a, [CTR] )

Final output:

vjianbolimsft_1-1669106664162.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The measure look right, may I had, that Impressions or clicks are the sum of each lines of the last 7 days.

Meaning, I filtered by Start Date which doesn't show in the image, does it change the measure?

 

Sorry I'm quite new to all of this! And thank you for your help, really appriciated :).

Greg_Deckler
Super User
Super User

@jhlatinia Are Impressions and Clicks measures? If so, what are the formulas?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler, no they are normal number column data.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors