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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Boris_EmV
Frequent Visitor

Average per row by date

Hi,

I have this sample data:

DatePatientTreatIDCOGS
1/1/2023A11100
1/3/2023A11100
1/5/2023A11100
1/8/2023A11100
1/10/2023A11100
1/11/2023A1

1100

 

I would like to create a measure to calculate Average COGS per row. If I select for example 1/10/2023 I want to see 1100 / 6 (count of dates) or 183.3 in this row.

 

2024-02-22_15-07-16.png

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Boris_EmV ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_0-1708673600732.png

Create a measure

Average = 
VAR _COUNT = COUNTROWS(ALL('Table'))
RETURN
    IF(
        ISFILTERED('Table'[COGS]),
        SELECTEDVALUE('Table'[COGS])/_COUNT,
        SELECTEDVALUE('Table'[COGS])
    )

Final output

vheqmsft_1-1708673919578.png

vheqmsft_2-1708673937970.png

 

Best regards,

Albert He

 

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

Hi @Boris_EmV 
sorry, my bad, I made a mistake. It should of course be 

CALCULATE( COUNTROWS( Table ), ALL( Table ) )

While you could also shorten it to this:

COUNTROWS( ALL( Table ) )

 


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Boris_EmV ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_0-1708673600732.png

Create a measure

Average = 
VAR _COUNT = COUNTROWS(ALL('Table'))
RETURN
    IF(
        ISFILTERED('Table'[COGS]),
        SELECTEDVALUE('Table'[COGS])/_COUNT,
        SELECTEDVALUE('Table'[COGS])
    )

Final output

vheqmsft_1-1708673919578.png

vheqmsft_2-1708673937970.png

 

Best regards,

Albert He

 

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

 

timalbers
Super User
Super User

Hi @Boris_EmV 


try something like this:

_measure =
    VAR nr_of_dates = CALCULATE( COUNTROWS( Table[Date] ), ALL( Table ) )
    VAR avg_cogs = SUM( Table[COGS] ) / nr_of_dates
    RETURN avg_cogs

 

Cheers

Tim


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

Thanks. I've tried similar measure like:

_measure =
    VAR nr_of_dates = CALCULATE( COUNT( Table[Date] ), ALL( Table[Date]) )
    VAR avg_cogs = SUM( Table[COGS] ) / nr_of_dates
    RETURN avg_cogs

 

It is showing correct values 183.3 by row and total is correct, but when I use slicer for dates (slicer is my calendar dimention connected to the table) is showing again 1100 at this date (10 Oct) for example. 

Hi @Boris_EmV 
sorry, my bad, I made a mistake. It should of course be 

CALCULATE( COUNTROWS( Table ), ALL( Table ) )

While you could also shorten it to this:

COUNTROWS( ALL( Table ) )

 


—————————————————————————————
✔️ If my answer helped you, please consider marking it as a solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.