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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

calculate the last 3 months from the selected date and the blank values that are 0

 

Hello everybody,

I need help. I have a model with a date dimension with INT field related to the fact table. In turn I have a dim period, with weekly and monthly values. This dimension filters the fact table which in turn filters the fact table. In the fact table I have records for weekly values and for monthly values.

 

dcb_bero_2021_0-1624883049756.png

 

I am trying to paint in a graph of lines, the values of the last 6 weeks or 6 months depending if I have filtered the month or the week and its respective date value.

 

the dax is

 Nro Problemas = 
var weeks = CALCULATE(DISTINCTCOUNT('fact'[Id Problema]),all('dim calendario'), DATESINPERIOD('dim calendario'[fecha],SELECTEDVALUE('dim calendario'[fecha]),-42,DAY),'dim Periodo')
var months= CALCULATE(DISTINCTCOUNT('fact'[Id Problema]),all('dim calendario'), DATESINPERIOD('dim calendario'[fecha],SELECTEDVALUE('dim calendario'[fecha]),-6,MONTH),'dim Periodo')
return
IF(MAX('dim calendario'[id_Periodo]) = 10 --week
,weeks
,IF(MAX('dim calendario'[id_Periodo]) = 11 --month
,months))
 
dcb_bero_2021_1-1624883312884.png

I need to paint the blanks as 0. I have tried the IF (measure = blank (), 0, measure) thing. But it paints me 0 on all dates. Whether from period 10 (week) or period 11 (month).

 

 

dcb_bero_2021_2-1624883465741.png

 

I need and hope to paint is this. Thanks

 

dcb_bero_2021_0-1624883739388.png

 

2 REPLIES 2
dedelman_clng
Community Champion
Community Champion

Hi @Anonymous -

 

Try adding +0 to the calculations in your measure

 

Nro Problemas =
VAR weeks =
    CALCULATE (
        DISTINCTCOUNT ( 'fact'[Id Problema] ),
        ALL ( 'dim calendario' ),
        DATESINPERIOD (
            'dim calendario'[fecha],
            SELECTEDVALUE ( 'dim calendario'[fecha] ),
            -42,
            DAY
        ),
        'dim Periodo'
    ) + 0       ////Adding +0 here
VAR months =
    CALCULATE (
        DISTINCTCOUNT ( 'fact'[Id Problema] ),
        ALL ( 'dim calendario' ),
        DATESINPERIOD (
            'dim calendario'[fecha],
            SELECTEDVALUE ( 'dim calendario'[fecha] ),
            -6,
            MONTH
        ),
        'dim Periodo'
    ) + 0       ////Adding +0 here
RETURN
    IF (
        MAX ( 'dim calendario'[id_Periodo] ) = 10 --week
        ,
        weeks,
        IF ( MAX ( 'dim calendario'[id_Periodo] ) = 11 --month
            , months )
    )

 

Hope this helps

David

Anonymous
Not applicable

Hi dedelman_clng,

Thanks for answering. This I already tried, but the result is the following.

 

dcb_bero_2021_0-1625218756375.png

It paints all the dates to 0 ... It is as if when putting the "+0", it did not respect the DATESINPERIOD.

 

Thanks.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.