Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Previous week data based on selected week from slicer

Hi guys,

 

I'm just learning the magic of PowerBi by building a weekly report.

However, I got stuck and I really hope you guys can point me in the right direction.

 

Simply put, my table has a column with created apps, and I want to visalize the distinct apps within a chosen period of time.

 

I have a measure for this:

Distinct Apps =
CALCULATE(DISTINCTCOUNT(AllData[AppId]))
 
I have WeekNumber column also, which is put in a slicer
WeekNumber = WEEKNUM(AllData[CreatedDate],2)
 
I created 4 new measures to get me the previous week data, but I can't figure it out why the last one does not work(it shows blank):
Selected Week = SELECTEDVALUE(AllData[WeekNumber])
 
Selected Week Distinct Apps =
var selectedWeek = SELECTEDVALUE(AllData[WeekNumber])
return CALCULATE([Distinct Apps], FILTER(AllData, AllData[WeekNumber]=selectedWeek))
 
Previous Week to Selected Week = SELECTEDVALUE(AllData[WeekNumber])-1
 
Last Week Distinct Apps =
calculate([Distinct Apps], FILTER((AllData), AllData[WeekNumber]=[Previous Week to Selected Week]))
This last measure should show the value 6, which corresponds for week 26, but it keeps showing blank, making me pull my hair off..
Can you please have a look and demistify what's going on and why I cannot display the previous week data, and how can i do that?
 
Thank you for your time!
Daniela

 

 

 


 
 
 
 
 
 
 
 
  • Hi Anonymous ,

    It is caused that the value is filtered by the slicer (Week = 27). You could try the following formula with the function of ALL. And you need to redefine the selected value in the measure.Because the measure of Previous Week to Selected Week is still affected by the slicer.

    Last Week Distinct Apps = 
    var a = SELECTEDVALUE(AllData[WeekNumber])
    return
    CALCULATE(DISTINCTCOUNT(AllData[AppId]), FILTER(ALL(AllData), AllData[WeekNumber] = a-1))

    Best Regards,

    Xue Ding

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

     

     

3 Replies

  • v-xuding-msft's avatar
    v-xuding-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

    It is caused that the value is filtered by the slicer (Week = 27). You could try the following formula with the function of ALL. And you need to redefine the selected value in the measure.Because the measure of Previous Week to Selected Week is still affected by the slicer.

    Last Week Distinct Apps = 
    var a = SELECTEDVALUE(AllData[WeekNumber])
    return
    CALCULATE(DISTINCTCOUNT(AllData[AppId]), FILTER(ALL(AllData), AllData[WeekNumber] = a-1))

    Best Regards,

    Xue Ding

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

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello v-xuding-msft and thank you millions for your interest and reply!

       

      You are magnificent, you helped me a lot!

      I was able to solve my issue by following your formulas and adding yet another filter.

      What I forgot to mention was that I had a global filter by the [Origin] of the app.

      Therefore, using ALL function ignored this filter and returned the total unique values of last week.

       

      This [Origin] column was in another table, so I related my AllData table with that column:

      AllData[Origin] = RELATED(Application[Origin])

       

      I figured I can add a second filter to the calculate function to keep that filter running.

      And TA-DAAA, it gave me the previous week unique values filtered by origin :), like below:

      Last Week Distinct Apps = 
      var a = SELECTEDVALUE(AllData[WeekNumber])
      return
      CALCULATE(DISTINCTCOUNT(AllData[AppId]), FILTER(ALL(AllData), AllData[WeekNumber] = a-1), FILTER(ALL(AllData), AllData[Origin] = "origin1")

       

      Without your explanation, I would have been stuck forever!

      So thank you so so so much!

       

      Have great day,

      Daniela

      • Anonymous's avatar
        Anonymous
        Not applicable

        How to handle end of year where week 52 becomes week 1