Forum Discussion
Comparing week with pervious week
I see you've encountered some issues with the filter not being applied to the prior week. Let's address this concern and also discuss how to add another filter to your DAX expression.
Addressing Filter Issue:
It appears that you are trying to filter the data based on the 'DateTable'[WeekIndex] for the prior week. Ensure the following:
Verify WeekIndex Field Type:
- Make sure that 'DateTable'[WeekIndex] is of the correct data type (possibly an integer) and represents weeks appropriately.
Check DateTable Relationship:
- Confirm that there is a proper relationship between 'DateTable' and 'TransactionTable' based on the date fields.
Ensure WeekIndex Exists:
- Double-check that there is data for the prior week in your 'DateTable' with the corresponding 'WeekIndex.'
Adding Another Filter:
To add another filter, you can indeed extend your DAX expression as you've attempted in the blue section. However, it seems like there might be a mistake with the placement of the CROSSFILTER function.
Here's a modified version:
Sum of Amount =
CALCULATE (
SUM ( TransactionTable[Amount] ),
FILTER (
ALL ( 'DateTable' ),
'DateTable'[WeekIndex] = SELECTEDVALUE('DateTable'[WeekIndex]) - 1
),
FILTER ( TransactionType, TransactionType[Type] = "1" ),
FILTER (
CancelledTable,
CancelledTable[CancelledFlag] <> TRUE
),
CROSSFILTER ( 'DateTable'[TransactDate], 'TransactionTable'[TDate], NONE )
)
Make sure that the CROSSFILTER is outside the FILTER block for 'CancelledTable' to ensure it applies to the entire CALCULATE context.
If the issues persist, consider examining your data, relationships, and data types more closely. Additionally, you can use tools like DAX Studio to evaluate and debug your DAX expressions.
thanks so much for your input. My index is definatly a continious list with no gaps.
I will try the alternative you suggest below.
thanks again
- 123abc2 years agoCommunity Champion
You're welcome! If your week index is a continuous list without gaps, and you have correctly defined relationships between your tables, the modified DAX expression I provided should work for filtering the sum of amounts for the previous week.
Feel free to give it a try, and if you encounter any further issues or have additional questions, don't hesitate to ask. Good luck with your Power BI project!
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.