Forum Discussion
Count valid items on date between startdate and enddate
- 5 years ago
Hi Rovisonn ,
>>What I want to do is the following. I would like to select any given date from my date/calendar table. Or just any given date in history possible. For this date I would like to know which contracts from the contrac table were valid on this date. Meaning the validfrom <= selected date and the validto >= the selected date. More specifically I would like to count the valid contracts for each city.
Please try to create a measure and add it to visual level filter:
Measure = IF(HASONEVALUE('Table'[Date]),IF(MAX(contract[Vaildfrom])<=MIN('Table'[Date])&&MAX(contract[Vaildto])>=MAX('Table'[Date]),1,0),1)>>And I would also like to know what the total rent amount is for each valid contract on that given date. Meaning the sum amount where validfrom <= selected date and validto >= selected date.
You can use the following measure to calculate total rent amount:
rent amount = VAR a = MAX ( 'Table'[Date] ) VAR b = SUMX ( SUMMARIZE ( 'rent price lines', contract[Contract ID], 'rent price lines'[Rent type], 'rent price lines'[Validfrom], 'rent price lines'[Validto], 'rent price lines'[Amount], "rent value", IF ( a >= 'rent price lines'[Validfrom] && a <= 'rent price lines'[Validto], 'rent price lines'[Amount], 0 ) ), [rent value] ) RETURN IF ( b = 0, "invalid", b )For more details, please refer to the pbix file:https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdDOewRVgntFmoxvsCvhKjQBmUYBB9NzjSr2VPwBJLN70g?e=320JT5
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
Hi Rovisonn ,
>>What I want to do is the following. I would like to select any given date from my date/calendar table. Or just any given date in history possible. For this date I would like to know which contracts from the contrac table were valid on this date. Meaning the validfrom <= selected date and the validto >= the selected date. More specifically I would like to count the valid contracts for each city.
Please try to create a measure and add it to visual level filter:
Measure = IF(HASONEVALUE('Table'[Date]),IF(MAX(contract[Vaildfrom])<=MIN('Table'[Date])&&MAX(contract[Vaildto])>=MAX('Table'[Date]),1,0),1)
>>And I would also like to know what the total rent amount is for each valid contract on that given date. Meaning the sum amount where validfrom <= selected date and validto >= selected date.
You can use the following measure to calculate total rent amount:
rent amount =
VAR a =
MAX ( 'Table'[Date] )
VAR b =
SUMX (
SUMMARIZE (
'rent price lines',
contract[Contract ID],
'rent price lines'[Rent type],
'rent price lines'[Validfrom],
'rent price lines'[Validto],
'rent price lines'[Amount],
"rent value",
IF (
a >= 'rent price lines'[Validfrom]
&& a <= 'rent price lines'[Validto],
'rent price lines'[Amount],
0
)
),
[rent value]
)
RETURN
IF ( b = 0, "invalid", b )
For more details, please refer to the pbix file:https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdDOewRVgntFmoxvsCvhKjQBmUYBB9NzjSr2VPwBJLN70g?e=320JT5
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Dedmon Dai
Hello, Is the pbix still accessible?I am getting 'This site can’t be reached' error, I just would like to understand Cal date is connected to valid from date or valid to date.