Forum Discussion

KanisleS's avatar
KanisleS
Helper I
4 years ago

[dax] subtotal wrong - need help with context filter

Hello guys,

 

I have a matrix that shows wrong subtotals, I believe it's because of the context filters but I don't really get what I should change.

I have 2 tables : Calendar table & Fact table ( 1:* relationship on day )

My fact table contains the number of sales made hourly.

I'm trying to do a prediction with a rolling average, I created this measure : 

2_months_prediction = CALCULATE(AVERAGEX(VALUES('Calendar'[WEEKS]),CALCULATE('FactTable'[NumberOfSales])),DATESINPERIOD('Calendar'[Date],max('Calendar'[Date])-7,-56,day))
 
And to compute the percentage of error I created this measure :
difference (%) = 1-DIVIDE([2_months_prediction],'FactTable'[NumberOfSales])
 
After that I wanted to count hourly ( and hierarchly daily weekly...) whether the prediction was good or bad, so i created these measures :
 Good = COUNTROWS(FILTER(VALUES('FactTable'[Hour]),ABS([difference (%)])<=0.2))
 Bad = COUNTROWS(FILTER(VALUES('FactTable'[Hour]),ABS([difference (%)])>0.2))
% Good = Divide ( [Good], [Good]+[Bad])
 
If I don't use the week filter I get wrong results.
In the matrix, the numbers next to the name of the days are correct but if I move further down to hours I get wrong numbers, it is not correctly filtered.
The subtotal is also wrong.
 
Any idea on what am I doing wrong and how could I fix this?
 
 
 
 
 

 

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi KanisleS ,

     

    Do you mean that when you drill down to hour level, you will get incorrect result from measure?  Is is part in screenshot incorrect? I couldn't see subtotal to this level in your screenshot. I think you can try 

    IF() and ISINSCOPE() function to calcualte in different hierarchy levels.

    I think your calculate is based on your data model. Please share a sample file with me and show me a screenshot with the result you want. This will make it easier for me to find the solution.

     

    Best Regards,
    Rico Zhou

     

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

     

    • KanisleS's avatar
      KanisleS
      Helper I

      Anonymous Thanks for your answer.

      I made a pbix sample file with randomized data : file 

      In the matrix with good/bad columns, if i drill down to hours and days the values are correct but the weekly values are wrong because they aren't the sum of the daily values, I want to fix that problem, the Total is also wrong since it doesn't compute the total sum of good/bad..

       

      exemple week 2021s13 : Good should be equal to 10+7+11+12+9+13+11

      I don't know where resides the problem, please let me know if you have an idea.

      thanks!