Forum Discussion
Dont Bring Blank
Hi All!
i have this Measure:
My data does not always reach the present day
Sometimes the current day is the 18th of the month and the data is only updated until the 12th of the month.What happens is that the formula divides the money by 18 instead of 12 and that's how I get a wrong average
Is it possible to add to the Measure that will not Bring in empty cells mean Blank?
Then no matter what day I am in the month it will only count up to where the data is
Thanks!
This is a better measure replacing the >0
Net USD AVG = VAR NumDays= CALCULATE ( DISTINCTCOUNT ('DB 2022'[Date] ), KEEPFILTERS( 'Date'[Date] < TODAY() ), NOT ISBLANK ( 'DB 2022'[Net USD] ), REMOVEFILTERS ( 'SORT GL' ) ) VAR SumNet = CALCULATE ( SUM ( 'DB 2022'[Net USD] ), KEEPFILTERS( 'Date'[Date] < TODAY() ) ) RETURN DIVIDE (SumNet, NumDays)In your 'DB 2022' table you have rows for every date whether there is a value for [Net USD] or not. My original measure went for >0 just to make sure it was picking days with values. The above version is better in case you did get negative values.
The reason it wasn't working when the sort field is added in is there are days in each month when there are no values for that particular sort. It was therefore not including that day in the division for that section. By using the REMOVEFILTERS ( 'Sort GL' ) it says no matter what sort is selected divided by the total number of days in the whole period.
14 Replies
- bcdobbs
Community Champion
Would this work: (Hard to test without a demo file)
Net USD AVG = CALCULATE( DIVIDE( SUM( 'DB 2022'[Net USD] ), DISTINCTCOUNT( 'DB 2022'[Date] ) ), KEEPFILTERS( 'Date'[Date] < TODAY() ) )
Replace 'DB 2022'[Date] with the date column on your table.- bcdobbs
Community Champion
Or depending on how big your fact table is this might be faster:
Net USD AVG = CALCULATE( AVERAGEX ( VALUES ( 'Date'[Date] ), CALCULATE ( SUM ( 'DB 2022'[Net USD] ) ) ), KEEPFILTERS( 'Date'[Date] < TODAY() ) ) - bcdobbs
Community Champion
Are you able to share some dummy data in the same table structure. Can't quite picture why it doesn't work.
Feel I'm missing something I think averagex and what you're trying to do will do the same thing.
- bcdobbs
Community Champion
The following two measures both give the desired 6076K.
Net USD AVG = VAR NumDays= CALCULATE ( DISTINCTCOUNT ('DB 2022'[Date] ), KEEPFILTERS( 'Date'[Date] < TODAY() ), 'DB 2022'[Net USD] > 0 ) VAR SumNet = CALCULATE ( SUM ( 'DB 2022'[Net USD] ), KEEPFILTERS( 'Date'[Date] < TODAY() ) ) RETURN DIVIDE (SumNet, NumDays)My prefered way is to go with the averagex. Yours wasn't working because you'd gotten rid of the outer calculate. With the demo data you sent both give the same values for each year:
Net USD AVG 2 = CALCULATE ( AVERAGEX( VALUES( 'Date'[Date] ), CALCULATE( SUM( 'DB 2022'[Net USD] ) ) ), KEEPFILTERS( 'Date'[Date] < TODAY() ) )
You need the outer calculate to remove future dates from the filter context. The inner calculate then causes context transition to happen so you get the SUM for each day.- netanel
Post Prodigy
First thanks for your time
But both do not work
If you go to 2021 and switch between the two Measure (NET USD AVG, AND NET USD AVG 2)
You will see that Other for FS is a large amount at the monthly level
That's why I used Divide- bcdobbs
Community Champion
So are you happy that the division version gives the right values? If so that's great.
I'm just really confused because on mine both give the same values: