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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Joerg
Helper I
Helper I

Measure to calculate zero values

Dear All

I have 2 tables, a table with periods and the other with values and dates.

 

period.pngvalues.png

The relation between both are columns "YYYY-MM" and "YearMonth".

 

When I put in a matrix column "YYYY-MM" and "Value" I get the sums for each month.

But I am missing the column for "2021-07", I have expected to see a zero because for that month no Values are existing.

How can I achive this with a measure ?

 

matrix.png

 

And a second question.

I have a slicer for the "YYYY-MM" column. Additionally a table MonthBack with values of 3; 6; 9 and 12.

Is it possible to select with the slicer a month and the matrix only shows values for this selected month and the number of choosen MonthBack ?

E.g. when I select 2021-06 and have the value MonthBack of 6, the matrix shows me the values from 2021-01 to 2021-06 ?

 

I would like to attach a pbix file for your reference, but there is no possibility for me to upload it.

 

Thanks for your help.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Joerg ,

I updated my sample pbix file(see attachment), please check whether that is what you want.

1. Create another yearmonth dimension table(Don't create any relationship with another tables) and apply the yearmonth field as slicer

Yearmonth = VALUES('Period'[YYYY-MM])

2. Create two measures as below to get the sum of values

TempsValue = 
VAR _selym =
    SELECTEDVALUE ( 'Yearmonth'[YYYY-MM] )
VAR _selyyyymm =
    SELECTEDVALUE ( 'Period'[YYYY-MM] )
VAR _ymvalue =
    VALUE ( CONCATENATE ( LEFT ( _selym, 4 ), RIGHT ( _selym, 2 ) ) )
VAR _svalue =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[YearMonth] = SELECTEDVALUE ( 'Period'[YYYY-MM] )
                && VALUE (
                    CONCATENATE ( LEFT ( 'Table'[YearMonth], 4 ), RIGHT ( 'Table'[YearMonth], 2 ) )
                ) <= _ymvalue
        )
    )
RETURN
    IF ( _selyyyymm <= _selym, _svalue + 0, BLANK () )
Sum of value = SUMX(VALUES('Period'[YYYY-MM]),[TempsValue])

3. Create matrix visual (Columns: YYYY-MM(from the table with period info)  Values:[Sum of value])

yingyinr_0-1629194918573.png

Best Regards

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

@Joerg 

For the cumulative rolling total to repeat over the months with 0

 

Try this:

 

Cumulative Sales =

IF(MIN(Period[YYYY-MM])<=CALCULATE(MAX(Yearmonth[YYYY-MM]),
ALL(Yearmonth)),CALCULATE([Sum of value],
FILTER(All(Period[YYYY-MM]),Period[YYYY-MM]<=MAX((Period[YYYY-MM])))),
BLANK())
 
 

@ Rena

@ Niiru1

 

Thanks to you both, your proposals are good input for me. The only thing is my requirement for a selection of the period to be displayed.

 

Let me explain.

I need a measure showing me for each period the value, if blank it should show zero. This is as per Rena's solution fine.

Also I need the same but with accumulated values, this works fine with the solution from Niiru1.

What I now need is an independent slicer where I can select a period, and the table shows me the values for that period and the following 5 months. The aggregation should stay as it is, only the view should be filtered.

 

2021-09-06 09_01_39-Mappe1 - Excel.png

How can I achieve that ? I tried myself to adapt this, but my knowledge is too limited.

 

Thanks for your help.

@ Niiru1

Thanks for this approach, it works if I do not care about the period.

But my requirement is, that I can control via an independent slicer which range of period I do display in the matrix. 

Anonymous
Not applicable

Hi @Joerg ,

I created a sample pbix file(see attachment), please check whether that is what you want.

1. Create a measure as below

Measure = SUM('Table'[Value])+0

2. Create a matrix visual (Columns: YYYY-MM (from the table with period)), Values: Measure)

yingyinr_0-1629183201610.png

In addition, you can refer the solution in the following threads to get it. The solution is to create or have a dimension table first, then create the measure and process the blank values. There are three main approaches.

Display zero instead of blank in matrix

Measure = SUM('Table'[Colname])+0 
Measure = IF ( ISBLANK ( SUM ( 'Table'[Colname] ) ), 0, SUM ( 'Table'[Colname] ) )
Measure = COALESCE ( SUM ( 'Table'[Colname] ), 0 )

Best Regards

Thanks, this works.

Maybe you have a solution for my second question as well ?

Anonymous
Not applicable

Hi @Joerg ,

I updated my sample pbix file(see attachment), please check whether that is what you want.

1. Create another yearmonth dimension table(Don't create any relationship with another tables) and apply the yearmonth field as slicer

Yearmonth = VALUES('Period'[YYYY-MM])

2. Create two measures as below to get the sum of values

TempsValue = 
VAR _selym =
    SELECTEDVALUE ( 'Yearmonth'[YYYY-MM] )
VAR _selyyyymm =
    SELECTEDVALUE ( 'Period'[YYYY-MM] )
VAR _ymvalue =
    VALUE ( CONCATENATE ( LEFT ( _selym, 4 ), RIGHT ( _selym, 2 ) ) )
VAR _svalue =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[YearMonth] = SELECTEDVALUE ( 'Period'[YYYY-MM] )
                && VALUE (
                    CONCATENATE ( LEFT ( 'Table'[YearMonth], 4 ), RIGHT ( 'Table'[YearMonth], 2 ) )
                ) <= _ymvalue
        )
    )
RETURN
    IF ( _selyyyymm <= _selym, _svalue + 0, BLANK () )
Sum of value = SUMX(VALUES('Period'[YYYY-MM]),[TempsValue])

3. Create matrix visual (Columns: YYYY-MM(from the table with period info)  Values:[Sum of value])

yingyinr_0-1629194918573.png

Best Regards

Hello

Would it be possible to show the values as a running total ?

Like the second row here ?

2021-09-03 14_09_26-Greenshot Editor.png

Hello,

that is awesome, thanks a lot 😀

amitchandak
Super User
Super User

@Joerg , You can add +0 to the measure. It might give all months.

 

try a code like this

 

0 between range
Measure = var _1= SUM(Opportunity[Opportunity count]) +0
var _min = minx(ALLSELECTED('Calendar'), 'Calendar'[Date])
var _max = maxx(ALLSELECTED('Calendar'), 'Calendar'[Date])
return
CALCULATE(if(max('Calendar'[Date]) <_min || max('Calendar'[Date]) >_max , BLANK(), _1))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks for your reply.

Unfortunately it still misses the month where no values exist

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.