Forum Discussion
Sum data based on date range
- 9 years ago
Hi digant,
I tried changing both Crosss filter direction Performance - Trade & Trade - Calendar relationships to Single, but still can not define relationship between( not even single) Perfmance - Date table.
In this scenario, you can create an inactive relationship between Performance - Date table like below.
Then you should be able to create a measure to calculate the sum of Performance[Pnl] using USERELATIONSHIP Function (DAX), and show the measure on the report with other columns.
PnlVolume = CALCULATE ( SUM ( Performance[Pnl] ), USERELATIONSHIP ( 'Date'[Date], Performance[PnlDate] ) )Here the sample pbix file for your reference.:smileyhappy:
Regards
Hi digant
I have a working solution but only IF the TradeID column is unique in your TRADE table.
If it is, create a relationship between Trade and Performance on TradeID (Trade = oneside and Performance = Many side)
Then just add the following calculated column to the Trade Table
New Column = CALCULATE(SUM('Performance'[Pnl]))
Hi Phil_Seamark
Thank you for your reply, but I can not add all three relationship together.
1) Many to one relationship between Trade and Calendar table
2) Many to one relationship between Performance and Calendar table
3) Many to one relationship between Performance to Trade table on TRADEID
If I deactivate Performance and Calendar relation to add third relation then Performance data doesn't respect date filters.
TRADE
| TradeID | TradeVolume | TradeExecuted |
| 1 | 5000 | 1/01/2016 |
| 2 | 10000 | 2/01/2016 |
| 3 | 7000 | 20/01/2016 |
| 4 | 12000 | 1/01/2016 |
Performance
| TradeID | Pnl | PnlDate |
| 1 | 100 | 1/01/2016 |
| 1 | 200 | 2/01/2016 |
| 1 | 300 | 15/01/2016 |
| 2 | 3000 | 2/01/2016 |
| 4 | 300 | 2/01/2016 |
| 4 | 400 | 3/01/2016 |
| 4 | 500 | 7/01/2016 |
| 4 | 900 | 1/01/2016 |
POWER BI(Date selected 1st JAN)
| TradeExecuted | TradeID | TradeVolume | Pnl |
| 1/01/2016 0:00 | 1 | 5000 | 600(Correct 100) |
| 1/01/2016 0:00 | 4 | 12000 | 2100(Correct 0) |
Thank you !!
regards,
Digant
- Phil_Seamark9 years agoMicrosoft Employee
Are any of the relationships BI -Directional? Make sure they are set to Single
- digant9 years agoHelper I
Hi Phil_Seamark,
I tried changing both Crosss filter direction Performance - Trade & Trade - Calendar relationships to Single, but still can not define relationship between( not even single) Perfmance - Date table.
regards,
Digant
- v-ljerr-msft9 years agoMicrosoft Employee
Hi digant,
I tried changing both Crosss filter direction Performance - Trade & Trade - Calendar relationships to Single, but still can not define relationship between( not even single) Perfmance - Date table.
In this scenario, you can create an inactive relationship between Performance - Date table like below.
Then you should be able to create a measure to calculate the sum of Performance[Pnl] using USERELATIONSHIP Function (DAX), and show the measure on the report with other columns.
PnlVolume = CALCULATE ( SUM ( Performance[Pnl] ), USERELATIONSHIP ( 'Date'[Date], Performance[PnlDate] ) )Here the sample pbix file for your reference.:smileyhappy:
Regards