cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AGo
Helper V
Helper V

Condition a measure by what is in scope in the graph

I've got an histogram with MeasureA=SUM([ValueA]) by Year and Month based on fields on TableA.

I've got TableB with field [ValueB] and MeasureB=SUM([ValueB]).

I would like to create a MeasureC=MeasureA+MeasureB where MeasureB adds its value on the histogram only on current year bar or current year and current month.

 

Is it possible?

Thanks in advance

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @AGo 

 

Based on your description, I created data to reproduce your scenario.

Table A:

d1.png

Table B:

d2.png

 

You may create measures as follows.

 

MeasureA = SUM('Table A'[ValueA])

MeasureB = SUM('Table B'[ValueB])

MeasureC = 
var _currentmonth = MONTH(TODAY())
var _currentyear = YEAR(TODAY())
var _date = MAX('Table A'[Date])

return
IF(
   MONTH(_date) = _currentmonth&&YEAR(_date)=_currentyear,
   CALCULATE(
       [MeasureA],
       FILTER(
           ALL('Table A'),
           'Table A'[Date].[MonthNo] = _currentmonth&&'Table A'[Date].[Year]=_currentyear
       )
   )+
   CALCULATE(
       [MeasureB],
       FILTER(
           ALL('Table B'),
           'Table B'[Date].[MonthNo] = _currentmonth&&'Table B'[Date].[Year]=_currentyear
       )
   ),
   [MeasureA]
) 

 

 

Result:

d3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @AGo 

 

Based on your description, I created data to reproduce your scenario.

Table A:

d1.png

Table B:

d2.png

 

You may create measures as follows.

 

MeasureA = SUM('Table A'[ValueA])

MeasureB = SUM('Table B'[ValueB])

MeasureC = 
var _currentmonth = MONTH(TODAY())
var _currentyear = YEAR(TODAY())
var _date = MAX('Table A'[Date])

return
IF(
   MONTH(_date) = _currentmonth&&YEAR(_date)=_currentyear,
   CALCULATE(
       [MeasureA],
       FILTER(
           ALL('Table A'),
           'Table A'[Date].[MonthNo] = _currentmonth&&'Table A'[Date].[Year]=_currentyear
       )
   )+
   CALCULATE(
       [MeasureB],
       FILTER(
           ALL('Table B'),
           'Table B'[Date].[MonthNo] = _currentmonth&&'Table B'[Date].[Year]=_currentyear
       )
   ),
   [MeasureA]
) 

 

 

Result:

d3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

JarroVGIT
Resident Rockstar
Resident Rockstar

Well yes but that really depends on your datastructure to have an exact answer. It will be somewhere along the lines of this:

MeasureC =
VAR _curSelectedYear = YEAR(MAX(Table[Date]))
VAR _curSelectedMonth = MONTH(MAX(Table[Date]))
VAR _currentYear = YEAR(TODAY())
VAR _currentMonth = MONTH(TODAY())
VAR _toAdd = IF(_curSelectedYear = _currentYear && _curSelectedMonth = _currentMonth, [MeasureB], 0)
RETURN
[MeasureA] + _toAdd

SOmething like this?

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
September Update

Check it Out!

Click here to learn more about the September 2022 updates!

Power BI Show Episode 10 Recap

The Power BI Community Show

Watch the playback when Amit Chandak, a Power BI Super User, demos how to use Field Parameters to make reports more dynamic.

Power BI Dev Camp Session 26

New Date - Check it Out!

Mark your calendars and join us on Thursday, October 6 at 11a PDT for a great session with Ted Pattison!

Health and Life Sciences Power BI User Group

Health and Life Sciences Power BI User Group

Power BI specialists at Microsoft have created a community user group where customers in the provider, payor, pharma, health solutions, and life science industries can collaborate.

Top Solution Authors