Forum Discussion
Measure to calculate sum but include rows based on dates
- 3 years ago
Hi , kmistry
Thanks for your sample pbix file first!
According to your description, you want to show the according Resource in your Matric visual.
I download your pbix file and see the relationship for your tabls are using the [Date] to [endDate]. This is why your table visual show only two resources.
For your needs, you want to use slicers to display custom resources, so you cannot create an active relationship.
Then i modify your [Column Values] measure as the judgement.
Column Values = VAR _startDate = CALCULATE( MIN('Resource Forecasting'[Resources -- Start Date (Actual)]), ALL('Date')) VAR _endDate = CALCULATE( MIN('Resource Forecasting'[Resources -- ETA Go-live (current tracking)]), ALL('Date')) VAR _period = MIN('Date'[Date]) >= _startDate && MAX('Date'[Date]) <= _endDate RETURN //IF(_period, 1) _periodWe can create two measures like this:
Measure = var _t = ADDCOLUMNS( CROSSJOIN( VALUES('Resource Forecasting'[Title]) , VALUES('Date'[Year-Month])) , "flag" ,IF( [Column Values] =FALSE(),0,1) ) return IF(SUMX(_t,[flag])>0 ,1,-1)Total Capacity-2 = var _t = ADDCOLUMNS( CROSSJOIN( VALUES('Resource Forecasting'[Title]) , VALUES('Date'[Year-Month])) , "flag" ,IF( [Column Values] =FALSE(),0,1) ) var _t2=ADDCOLUMNS(FILTER( GROUPBY(_t , [Title] , "sum_flag" , SUMX(CURRENTGROUP(),[flag])),[sum_flag]>0) , "total" , [Total Capacity]) return sumx(_t2,[total])Then we can put the mesure on the "Filter on this visual" for your table visual:
And if your want to get the right total in your above table visual , we may use the [Total Capacity-2] measure in it:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , kmistry
Thanks for your sample pbix file first!
According to your description, you want to show the according Resource in your Matric visual.
I download your pbix file and see the relationship for your tabls are using the [Date] to [endDate]. This is why your table visual show only two resources.
For your needs, you want to use slicers to display custom resources, so you cannot create an active relationship.
Then i modify your [Column Values] measure as the judgement.
Column Values =
VAR _startDate =
CALCULATE(
MIN('Resource Forecasting'[Resources -- Start Date (Actual)]),
ALL('Date'))
VAR _endDate =
CALCULATE(
MIN('Resource Forecasting'[Resources -- ETA Go-live (current tracking)]),
ALL('Date'))
VAR _period = MIN('Date'[Date]) >= _startDate && MAX('Date'[Date]) <= _endDate
RETURN
//IF(_period, 1)
_period
We can create two measures like this:
Measure = var _t = ADDCOLUMNS( CROSSJOIN( VALUES('Resource Forecasting'[Title]) , VALUES('Date'[Year-Month])) , "flag" ,IF( [Column Values] =FALSE(),0,1) )
return
IF(SUMX(_t,[flag])>0 ,1,-1)Total Capacity-2 = var _t = ADDCOLUMNS( CROSSJOIN( VALUES('Resource Forecasting'[Title]) , VALUES('Date'[Year-Month])) , "flag" ,IF( [Column Values] =FALSE(),0,1) )
var _t2=ADDCOLUMNS(FILTER( GROUPBY(_t , [Title] , "sum_flag" , SUMX(CURRENTGROUP(),[flag])),[sum_flag]>0) , "total" , [Total Capacity])
return
sumx(_t2,[total])
Then we can put the mesure on the "Filter on this visual" for your table visual:
And if your want to get the right total in your above table visual , we may use the [Total Capacity-2] measure in it:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- kmistry3 years agoRegular Visitor
Thank you Aniya, this was exactly what I was looking for!