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
Rana_Rumeel
Helper II
Helper II

Calculate Average on bases of 31st December but Empty Result for other rows

Hi Everyone,

I have following measure to calculate Sales for same day of each month

00 - Sales_SameDay_EachMonth =
VAR PreviousYearFilter =
    YEAR ( TODAY () ) - 1
RETURN
    CALCULATE (
        SUM ( vw_Sale[Sales_Dollars] ),
        YEAR ( vw_SalesCollectionsCenter[Date - Sales] ) = PreviousYearFilter
    )

Here is the result of this measure

Rana_Rumeel_0-1714144880023.png

 
And here is the 2nd measure to calculate Sale for 31st date of each month for last year.

00 - Total Sales 31st of Last Year =
VAR PreviousYearFilter =
    YEAR ( TODAY () ) - 1
RETURN
    CALCULATE (
        SUM ( vw_Sale[Sales_Dollars] ),
        DAY ( vw_SalesCollectionsCenter[Date - Sales] ) = 31,
        YEAR ( vw_SalesCollectionsCenter[Date - Sales] ) = PreviousYearFilter
    )

 and here is the result of this measure

Rana_Rumeel_1-1714144968580.png

Now I created a 3rd measure to calculate the Average on the bases of these two measure

00 - Total Average =
DIVIDE (
    [00 - Sales_SameDay_EachMonth],
    [00 - Total Sales 31st of Last Year],
    0
)

and here is the result

Rana_Rumeel_2-1714145232134.png

I want to see the Average for each Date. but it is displaying only for 31st. Kindly suggest

3 REPLIES 3
v-yohua-msft
Community Support
Community Support

Hi, @Rana_Rumeel 

Based on your information, I created a table:

vyohuamsft_0-1714372524758.png

 

There's nothing wrong with your first and third measures. I modified your second measure, and my understanding is that you want to divide the data for each day of the month by the data for the last day of the month, so I created the following measure:

00 - Total Sales 31st of Last Year = 
CALCULATE (
    SUM ( 'Table'[Sales_Dollars]),
    FILTER (
        ALL ( 'Table' ),
       'Table'[Date - Sales] = EOMONTH ( MAX ( 'Table'[Date - Sales]), 0 )
    )
)

 

Here is my preview:

 

vyohuamsft_1-1714372903322.png

 

How to Get Your Question Answered Quickly 

Best Regards

Yongkang Hua

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

@v-yohua-msft Thank you for yur response.
I have two tables in my model
    1: vw_SalesCollectionsCenter[Date - Sales]
    2: vw_Sale[Sales_Dollars]

1st table contains Dimension information and contains a Date column
I am using only Day part to display sales only at Day level for each month for example
-------------------------------------------------------------------
1 = Sum Sale for 1st date of every month
2 = Sum Sale for 2nd date of each month
..
..
31 = Sum Sale for 31st of each month.
------------------------------------------------------------------

and 2nd table contains data for sales. there is a relationship on the bases of DateKey.

I need to divide Sales on 1st (Sum Sale for 1st date of every month from last year only)
by Sales on 31st (Sum Sale for 31st date of every month from last year)

kindly confirm if more clarity is required.

some_bih
Super User
Super User

Hi @Rana_Rumeel without model / and details it is hard to spot your issue.

Still, try 2 test measures (order of creation is important, so 00 - Total Average test is created last)

00 - Total Sales Last Year test =
VAR PreviousYearFilter =
YEAR ( TODAY () ) - 1
RETURN
CALCULATE (
SUM ( vw_Sale[Sales_Dollars] ),
YEAR ( vw_SalesCollectionsCenter[Date - Sales] ) = PreviousYearFilter
)

 

 

00 - Total Average test=
DIVIDE (
[00 - Sales_SameDay_EachMonth],
[00 - Total Sales Last Year test],
0
)





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

Proud to be a Super User!






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.