Forum Discussion
Anonymous
6 years agoNot applicable
Create custom fields that extracts values from a field
Hi, I have a data like the one below and i want to create two custom field (Sales Yesterday and Sales last Week) that extract values from the Sold field for any row whose TxnDate is equal to the ...
- 6 years ago
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. I used 7/17/2020 as test date on my side. You need to modify it as Today(). The pbix file is attached in the end.
You may creatd measures as below.
Last week Sales = var tab = SUMMARIZE( 'Table', 'Table'[Prroduct], "Result", var _testdate = DATE(2020,7,17) var _product = [Prroduct] return CALCULATE( SUM('Table'[Sold]), FILTER( ALL('Table'), 'Table'[Prroduct]=_product&& YEAR('Table'[TxnDate])=YEAR(_testdate)&& WEEKNUM('Table'[TxnDate])=WEEKNUM(_testdate)-1 ) ) ) var result = SUMX( tab, [Result] ) return IF( ISBLANK(result), 0, result ) YesterDay Sales = var tab = SUMMARIZE( 'Table', 'Table'[Prroduct], "Result", var _testdate = DATE(2020,7,17) var _product = [Prroduct] return CALCULATE( SUM('Table'[Sold]), FILTER( ALL('Table'), 'Table'[Prroduct]=_product&& 'Table'[TxnDate]=_testdate-1 ) ) ) var result = SUMX( tab, [Result] ) return IF( ISBLANK(result), 0, result )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-alq-msft
6 years agoCommunity Support
Hi, Anonymous
If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.
Best Regards
Allan