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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

DAX IDEA

Hi community,

 

Im trying to find a solution for a measure I created that allows me to have the SUM of the last 5 months from the chosen month in the slicer even if I have more months selected in the  Date slicer. For example:

 

On the slicer I have marked from "january 2018" to "december 2018" so I need to have the SUM from the last date chosen (December 2018) to (August 2018)... (In tha case I have the 5 months I need only)

 

and if I choose  to "january 2018" to "november 2018" get the sum from november to July... and so on...

 

 

Any help or advice would be so much appreciated.

 

 

5 LAST MONTHS ALTO BRUT RE TEST 2 = 
IF (
    SELECTEDVALUE ( 'LLAVE TIPO'[Tipo]; "Negocio" ) = "Negocio";
    CALCULATE (
        SUM ( 'Base Ventas Netas'[Cantidad] );
        'Base Ventas Netas'[Cantidad] = 1;
        'Base Ventas Netas'[Tabla Pyme] = ">600";FIRSTDATE(DATESINPERIOD('Base Ventas Netas'[Mes];LASTDATE('Base Ventas Netas'[Mes]);5;MONTH)
        ));
    CALCULATE (
        SUM ( 'Base Ventas Netas'[Cantidad] );
        'Base Ventas Netas'[Cantidad] = 1;
        'Base Ventas Netas'[RE/RP] = "RESTD";
        'Base Ventas Netas'[ISEE] IN { "ABC1"; "C2" };
        'Base Ventas Netas'[Tabla Persona]
            IN { "<400"; "<600"; "<700"; "<800"; "<900"; ">900" };FIRSTDATE(DATESINPERIOD('Base Ventas Netas'[Mes];LASTDATE('Base Ventas Netas'[Mes]);5;MONTH
    )
))
    + CALCULATE (
        SUM ( 'Base Ventas Netas'[Cantidad] );
        'Base Ventas Netas'[ISEE] = "NO DATA";
        'Base Ventas Netas'[Tabla Persona] = ">900";
        'Base Ventas Netas'[Cantidad] = 1;
        'Base Ventas Netas'[RE/RP] = "RESTD";FIRSTDATE(DATESINPERIOD('Base Ventas Netas'[Mes];LASTDATE('Base Ventas Netas'[Mes]);5;MONTH
    ))))

 

1 ACCEPTED SOLUTION
christianfcbmx
Post Patron
Post Patron

You need this @Anonymous  . ENJOY!!!

 

XXXX XXXX XXXX =
SELECTEDVALUE ( 'LLAVE TIPO'[Tipo]; "Negocio" ) = "Negocio";
CALCULATE (
SUM('Base Ventas Netas'[Cantidad]);
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP]="RPSTD";
'Base Ventas Netas'[Tabla Pyme] = ">600";ALL('Master Calendar);DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH)
);
CALCULATE (
SUM( 'Base Ventas Netas'[Cantidad] );
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP] = "RPSTD";
'Base Ventas Netas'[ISEE] IN { "ABC1"; "C2" };
'Base Ventas Netas'[Tabla Persona]
IN { "<400"; "<600"; "<700"; "<800"; "<900"; ">900" };ALL('Master Calendar;DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH))

 

+ CALCULATE (
SUM( 'Base Ventas Netas'[Cantidad] );
'Base Ventas Netas'[ISEE] = "NO DATA";
'Base Ventas Netas'[Tabla Persona] = ">900";
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP] = "RPSTD";ALL('Master Calendar);DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH))
)

View solution in original post

2 REPLIES 2
christianfcbmx
Post Patron
Post Patron

You need this @Anonymous  . ENJOY!!!

 

XXXX XXXX XXXX =
SELECTEDVALUE ( 'LLAVE TIPO'[Tipo]; "Negocio" ) = "Negocio";
CALCULATE (
SUM('Base Ventas Netas'[Cantidad]);
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP]="RPSTD";
'Base Ventas Netas'[Tabla Pyme] = ">600";ALL('Master Calendar);DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH)
);
CALCULATE (
SUM( 'Base Ventas Netas'[Cantidad] );
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP] = "RPSTD";
'Base Ventas Netas'[ISEE] IN { "ABC1"; "C2" };
'Base Ventas Netas'[Tabla Persona]
IN { "<400"; "<600"; "<700"; "<800"; "<900"; ">900" };ALL('Master Calendar;DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH))

 

+ CALCULATE (
SUM( 'Base Ventas Netas'[Cantidad] );
'Base Ventas Netas'[ISEE] = "NO DATA";
'Base Ventas Netas'[Tabla Persona] = ">900";
'Base Ventas Netas'[Cantidad] <>-1;
'Base Ventas Netas'[RE/RP] = "RPSTD";ALL('Master Calendar);DATESINPERIOD('Base Ventas Netas'[Mes];MAX('Base Ventas Netas'[Mes]
);-6;MONTH))
)
Anonymous
Not applicable

HI @Anonymous ,

Can you please share some sample data for test? it is hard to test with dax formula without sample data.

How to Get Your Question Answered Quickly  

In addition, you can also take a look at the following link to use date function to define filter range and calculate:
Time Intelligence "The Hard Way" (TITHW)  
Regards,

Xiaoxin Sheng

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.