cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndreaPRJ
Frequent Visitor

Show in a Table totals for max and min Year Selected in Filter..

..regardless of the year added in the tablecolumn.

Hi to all!

In my report I have a total of 6.594 calls divided as follows per year:

2019: 1138 

2020: 1535

2021: 2376

2022: 1545

I have a slicer with which the user can choose two years to compare and one simple table with these measures:

TotalCalls:= COUNT(CALLS[NUMEROSTEP])

MaxYear:=CALCULATE(TotalCalls;

    FILTER (ALLSELECTED(CALLS[DATE]);
    year(CALLS[DATE]) = [Max Year Selected]))

MinYear:=CALCULATE([TotalCalls];

    FILTER (ALLSELECTED(CALLS[DATE]);
    year(CALLS[DATE]) = [Min Year Selected]))
Max Year Selected = Max(CALLS[DATE].[Year])
Min Year Selected = Min(CALLS[DATE].[Year])
 
with NO filter selected:

Immagine 2022-05-03 155341.jpg

If I choose two years from the slicer, all ok! and I see 2.376 under Max Year and 1.535 under Min Year 

 

 

Immagine 2022-05-03 155502.jpg

 However, if I add the year ("Anno column in italian..)  in front of the existing fields in my table, the data begins to not come out as I would like, because I imagine the filter context of the year is added

 

 

Immagine 2022-05-03 155825.jpg

 

In the firt raw (YEAR 2020), I would like to see 2.376 under Max Year and 1.535 under Min Year

In the second raw (YEAR 2021), I would like to see the same

 

I tried with REMOVEFILTERS ,ISINSCOPE and others but i did not solve 😞

I'm just starting out with dax

 

The final objective will then be to show the data in a matrix with the Year \ Month structure on the left and as values ​​the two measures with the calls of the year max and year min

 

PS: how could I limit the choice in the year filter to ONLY two years and no more than two?

THANK YOU VERY MUCH in advance

 

 

1 ACCEPTED SOLUTION

Hi @AndreaPRJ 

You can try this, create the measures below,

Max Year Selected = MAXX(ALLSELECTED('Table'),'Table'[Year])
Min Year Selected = MINX(ALLSELECTED('Table'),'Table'[Year])
MaxYear = CALCULATE(MAX('Table'[Qty]),FILTER(ALL('Table'),'Table'[Year]=[Max Year Selected]))
MinYear = CALCULATE(MAX('Table'[Qty]),FILTER(ALL('Table'),'Table'[Year]=[Min Year Selected]))

result

vxiaotang_0-1652853572757.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

4 REPLIES 4
AndreaPRJ
Frequent Visitor

hi amitchandak, first of all thank you.

Unfortunately with your two measures I would get this .. with "holes".

Immagine 2022-05-04 091128.jpg

 

I would ALWAYS want both columns full, where the first shows me the number of calls for the maximum year among those selected and the second for the minimum year.

PS: the second option of your measurements would remove a couple of other active filters at the report level and therefore I do not take it into consideration

Bye

Hi @AndreaPRJ 

You can try this, create the measures below,

Max Year Selected = MAXX(ALLSELECTED('Table'),'Table'[Year])
Min Year Selected = MINX(ALLSELECTED('Table'),'Table'[Year])
MaxYear = CALCULATE(MAX('Table'[Qty]),FILTER(ALL('Table'),'Table'[Year]=[Max Year Selected]))
MinYear = CALCULATE(MAX('Table'[Qty]),FILTER(ALL('Table'),'Table'[Year]=[Min Year Selected]))

result

vxiaotang_0-1652853572757.png

 

Best Regards,

Community Support Team _Tang

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

Thank you very much and very sorry for the delay!

amitchandak
Super User
Super User

@AndreaPRJ , try like

 

MaxYear:=
Var _max = maxx(allselected('CALLS') , 'CALLS'[Year])
return
CALCULATE(TotalCalls;
FILTER (CALLS; year(CALLS[DATE]) = _max))

MinYear:=
Var _max = minx(allselected('CALLS') , 'CALLS'[Year])
return
CALCULATE(TotalCalls;
FILTER (CALLS; year(CALLS[DATE]) = _max))

 

 

or

 

MaxYear:=
Var _max = maxx(allselected('CALLS') , 'CALLS'[Year])
return
CALCULATE(TotalCalls;
FILTER (all(CALLS); year(CALLS[DATE]) = _max))

MinYear:=
Var _max = minx(allselected('CALLS') , 'CALLS'[Year])
return
CALCULATE(TotalCalls;
FILTER (all(CALLS); year(CALLS[DATE]) = _max))



New Power BI Features
Datamarts: https://youtu.be/8tskWsJTEpg
Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin !! Proud to be a Super User!
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors