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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Dynamic Filter of Same Column

Hi,

 

I need to calculate a formula wherein if I select Q1 2020 it must get divided by Q1 2019 ( previous year). 

The column has values like Q12020, Q22020, Q32020 and so on. Below is an idea how the formula should be
formula = SUM(Column 1) where period = Q12020 / SUM(Column 1) where period = Q12019

 

Please help me !!

1 ACCEPTED SOLUTION

hi @Anonymous 

This works on my side.

2.JPG3.JPG

 

and here is my sample pbix file, please try it.

 

Could you please share your sample pbix file, there should be something wrong in other.

 

Regards,

Lin

Community Support Team _ Lin
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

13 REPLIES 13
amitchandak
Super User
Super User

@Anonymous , in case you have date , you can use time intelligence with date calendar

Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))

Last complete QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD( ENDOFQUARTER(dateadd('Date'[Date],-1,QUARTER))))
Last to last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-2,QUARTER)))
Next QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],1,QUARTER)))
Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,Year)))
Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(ENDOFQUARTER(dateadd('Date'[Date],-1,Year))))
trailing QTR = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,QUARTER))

 

In case you do not have date - you can use qtr Rank // here date can be qtr table. But have it separate

Qtr Rank = RANKX(all('Date'),'Date'[Qtr Start date],,ASC,Dense)
This Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])))
Last Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1))
Last year Qtr = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=(max('Date'[Qtr Rank]) -4)))

 

Power BI — QTD
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839

 

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 :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


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
vanessafvg
Super User
Super User

that sounds a little confusing please share some dummy data with the result you are expecting.




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




MFelix
Super User
Super User

Hi @Anonymous ,

You need to create a measure similar to the one below:

 

Vaddlue =
VAR Year_Selected =
    RIGHT ( SELECTEDVALUE ( 'Table'[Quarter] ), 4 )
VAR Quarter_Selected =
    LEFT ( SELECTEDVALUE ( 'Table'[Quarter] ), 2 )
RETURN
    SUM ( 'Table'[Value] )
        / CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table'[Quarter] ),
                'Table'[Quarter] = Quarter_Selected & ( Year_Selected - 1 )
            )
        )

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi MFelix, Thanks for the suggestion, but it is not working. Let me reiterate the problem. Suppose you have a column with Qtr & Year value like Q1 2020, Q2 2020 and so on. So if I select Q1 2020, I should get the sum of other column lets call it 'A' of the period Q1 2019 which is same quarter but 1 year less. Somehow the code you hae shared is not working.

 

Thanks

Hi @Anonymous ,

 

Is the columns where you are filtering "Q1 2020" or "Q12020"

If you have a space in the middle you need to change the formula a little bit try this one:

 

Vaddlue =
VAR Year_Selected =
    RIGHT ( SELECTEDVALUE ( 'Table'[Quarter] ), 4 )
VAR Quarter_Selected =
    LEFT ( SELECTEDVALUE ( 'Table'[Quarter] ), 3 )
RETURN
    SUM ( 'Table'[Value] )
        / CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER (
                ALL ( 'Table'[Quarter] ),
                'Table'[Quarter] = Quarter_Selected & ( Year_Selected - 1 )
            )
        )

Using the value 3 on the LEFT formula you will pick up the "Q1 ".

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Thanks for the prompt response but I have already taken care of the space. I am getting infinity value using this formula.

HI  @Anonymous 

Getting infinity value means there is no value for last year for same quarter by this formula,

MFelix's formula should work, Please check if data is right, for example, filter Q12020 and Q12019 together to see if there is data in Q12019.

If you still have the problem, please share a simple sample pbix file, that will be a great help.

 

Regards,

Lin

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

Can you share the formula you are using please.

 

On the test I have made everything was working properly. 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

VAR Year_Selected =
RIGHT ( SELECTEDVALUE ( 'PowerBI'[Qtr_FY] ), 4 )
VAR Quarter_Selected =
LEFT ( SELECTEDVALUE ( 'PowerBI'[Qtr_FY] ), 3 )
RETURN
CALCULATE (
SUM ( 'PowerBI'[MRR] )
,FILTER (
ALL ( 'PowerBI'[Qtr_FY] ),
'PowerBI'[Qtr_FY] = Quarter_Selected & ( Year_Selected-2)
)
)

Annotation 2020-08-18 102439.png

hi @Anonymous 

This works on my side.

2.JPG3.JPG

 

and here is my sample pbix file, please try it.

 

Could you please share your sample pbix file, there should be something wrong in other.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

One question - the same formula is not working in my PBI because the column Qtr_FY is a calculated one not just the imported column?

Hi @Anonymous ,

 

The fact that yuou use a calculated column should not be an issue, and based on the information you are giving the calculation should be correct, can you share the MRR values so I can check it out. As describe in my previous answers and on the example given by @v-lili6-msft  the formula is working however this can be a problem with your model and canb e related with data format, filtering or some other context that can influence your measure.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



hi  @Anonymous 

I don't think this is problem that cause your error, if possible, share a simple sample pbix file, that will be a great help.

 

Regards,

Lin

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.

Top Solution Authors