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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Show the data for the latest week if all/nothing selected from slicer

Hello,

 

I have a table as shown in the pic1. I want to visualize the number of tasks per team and have a week slicer where I can select each week (pic2). It works normally but one thing I want to do is to show the data of the last week if I do not select anything from the slicer. I have written the following measure but it does not work. Another problem is that total row does not show the correct number if nothing is selected from the slicer. But it shows the correct number if I select one of the weeks from the slicer. Can you please help with the measure and this total row problem?

 

Thank you in advance!

 

 

 

Number of tasks = 
IF(
   CALCULATE (DISTINCTCOUNT ('Tasks'[Week of Year]), 
              ALLSELECTED ( 'Tasks'[Week of Year]) 
             ) =  CALCULATE ( DISTINCTCOUNT ('Tasks'[Week of Year]), 
                              ALL ( 'Tasks') 
                            ),

   CALCULATE(COUNTROWS('Tasks'),'Tasks'[Status] = "Implemented",
             FILTER('Tasks','Tasks'[Week of Year] = MAX(Tasks[Week of Year])
                   )
            ),

   CALCULATE(COUNTROWS('Tasks'),'Tasks'[Status] = "Implemented")
  )

 

 

 

1.PNGpic 2pic 2

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create measures like DAX below, and display [Number of tasks New] in your Table visual to replace the original measure.

 

Number of tasks= CALCULATE(COUNTROWS('Tasks'),FILTER('Tasks', 'Tasks'[Status] = "Implemented" &&'Tasks'[Week of Year] = MAX(Tasks[Week of Year])))



Number of tasks New=

Var _table = SUMMARIZE('Tasks',[Team],"_Value",[Number of tasks])

Var _SumTotal= IF(HASONEVALUE([Team]),[Number of task],SUMX(_table,[_Value]))

Var _LastWeek= CALCULATE(MAX( 'Tasks'[Week of Year]), ALLSELECTED( 'Tasks'[Week of Year]))

Var Data_LastWeek=CALCULATE ('Tasks'[Number of tasks], FILTER ( ALLSELECTED( 'Tasks'), 'Tasks'[Status] = "Implemented" &&  'Tasks'[Week of Year] =_LastWeek )) 


Return

IF( ISFILTERED('Tasks'[Week of Year] ), _SumTotal , Data_LastWeek)

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

2 REPLIES 2
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create measures like DAX below, and display [Number of tasks New] in your Table visual to replace the original measure.

 

Number of tasks= CALCULATE(COUNTROWS('Tasks'),FILTER('Tasks', 'Tasks'[Status] = "Implemented" &&'Tasks'[Week of Year] = MAX(Tasks[Week of Year])))



Number of tasks New=

Var _table = SUMMARIZE('Tasks',[Team],"_Value",[Number of tasks])

Var _SumTotal= IF(HASONEVALUE([Team]),[Number of task],SUMX(_table,[_Value]))

Var _LastWeek= CALCULATE(MAX( 'Tasks'[Week of Year]), ALLSELECTED( 'Tasks'[Week of Year]))

Var Data_LastWeek=CALCULATE ('Tasks'[Number of tasks], FILTER ( ALLSELECTED( 'Tasks'), 'Tasks'[Status] = "Implemented" &&  'Tasks'[Week of Year] =_LastWeek )) 


Return

IF( ISFILTERED('Tasks'[Week of Year] ), _SumTotal , Data_LastWeek)

 

Best Regards,

Amy 

 

Community Support Team _ Amy

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

 

parry2k
Super User
Super User

@Anonymous here are some links to work with week calculations

 

https://www.sqlbi.com/articles/week-based-time-intelligence-in-dax/

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.