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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
IF
Post Prodigy
Post Prodigy

New Column for rolling month with slicer

Hi,

I could not make a new column to get the values for the last three months. I checked from other forms, but mine doesn't work.

 

I have the main table:

 

Typedatetextdatevalueorder
a04.20204.1.202054
a04.20204.1.202044
a03.20203.1.202033
a02.20202.1.202022
a01.20201.1.202011
b04.20204.1.2020154
b04.20204.1.2020144
b03.20203.1.2020133
b02.20202.1.2020122
b01.20201.1.2020111
a12.201912.1.201910
b12.201912.1.2019100

 

I have also 2 more tables and use the slicers from there.

Type table

Type
a
b

 

Month table

 

DateTDateOrder
03.20203.1.20203
02.20202.1.20202
01.20201.1.20201
04.20204.1.20204
12.201912.1.20190

 

I use Type[Type] and Month[DateT] fields for two different slicers.

 

I wanted to make a new column:

Column= CALCULATE(COUNTROWS('Table'),DATESINPERIOD('Month'[date],LASTDATE('Month'[date]),-3,MONTH))
It doesn't work.
I tried:
SUM ( 'Table'[value] ),  FILTER ( ALL ( 'Month'[Order]), 'Month'[Order] >= SELECTEDVALUE ( 'Month'[Order] ) - 2
&& 'Month'[Order] <= SELECTEDVALUE ( 'Month'[Order] ) ) )
It didn't work either.
 
For example; if 04.2020 is and a type is selected, I was expecting to get result 4 (April:2 counts + march 1 count + Feb. 1 count)
Similarly; if the type is not selected I expect to get the result 8(April:4 counts + march 2 count + Feb. 2 count).
 
 I really appreciate it if I get an answer.
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @IF ,

 

Sorry for my late reply.

 

Please use this:

sum value =
CALCULATE ( SUM ( 'Table'[value] ), FILTER ( 'Table', [Flag] = 1 ) )

4.1.sum value.gif

Best Regards,
Eyelyn Qin


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

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @IF ,

 

According to my understanding, you want to count the number of rows based on the selected value of Type and DateT via slicers, right?

 

First,The value of calculated column is stored in the row that will not change according to the user selection-- Calculated column could not be dynamic.So It's suggested to create measure instead.

 

Second, you need to delect the relationships between the three tables so that you can custom the cross-filter by measure.

 

Please try the following formula:

Flag =
VAR _type =
    SELECTEDVALUE ( 'Type'[Type] )
VAR _datetext =
    SELECTEDVALUE ( 'Month'[DateT] )
VAR _date =
    DATE ( RIGHT ( _datetext, 4 ), LEFT ( _datetext, 2 ), 1 )
VAR _v1 =
    IF (
        MAX ( 'Table'[type] ) = _type
            && MAX ( 'Table'[date] ) <= _date
            && MAX ( 'Table'[date] ) > EOMONTH ( _date, -3 ),
        1
    )
VAR _v2 =
    IF (
        MAX ( 'Table'[date] ) <= _date
            && MAX ( 'Table'[date] ) > EOMONTH ( _date, -3 ),
        1
    )
RETURN
    IF ( _type <> BLANK (), _v1, _v2 )

Then use the SUMX() for Card visual:

Count Rows = SUMX('Table',[Flag])

The final output is shown below:

dynaimc.gif

 

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

Hi 

It works, but I also want to get the sum of Table[Value] for the last 3months based on the selection (same as the other measure. 

I tried this:

SumValue =
var a = [Flag]
return
CALCULATE(SUM('Table'[value]),a)
 
It didn't work if I use the measure "flag". I am not really good with power bi. Can you help me to get the sum of value (Table[Value]) with the same logic?
Anonymous
Not applicable

Hi @IF ,

 

Sorry for my late reply.

 

Please use this:

sum value =
CALCULATE ( SUM ( 'Table'[value] ), FILTER ( 'Table', [Flag] = 1 ) )

4.1.sum value.gif

Best Regards,
Eyelyn Qin


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

Perfect, thanks a lot!

amitchandak
Super User
Super User

@IF , best to have date table and use that. even if you have data of one day per month in your table

 

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date]),-3,MONTH))

 

or

 

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-1) ,-3,MONTH))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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

Hi,

I tried but didn't work. Can you check if I did smth wrong?

https://www.dropbox.com/s/zz0b6yiloezsduw/3%20month%20rolling%20second%20time.pbix?dl=0

Rolling 3 = CALCULATE(SUM('Table'[value]),DATESINPERIOD('Month'[Date],MAX('Month'[Date]),-3,MONTH))
Rolling 3 v2 = CALCULATE(SUM('Table'[value]),DATESINPERIOD('Month'[Date],EOMONTH(MAX('Month'[Date]), -1),-3,MONTH))
Thanks again!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors