Forum Discussion

Ynew's avatar
Ynew
Helper I
8 years ago
Solved

Referring A Measure inside Another Measure

Hi,

 

I have a problem with referring a measure in other measures. It seems that my second measure does not understand the reference, so could you generally explain a little bit about it?

And here is my specific question.

I have two tables, Table1 and Report1.

 

What if "Month" column in Table1 is like:

Month:

Jul

Aug

Sep

Oct

Nov

Dec

So this way Month column is sorted based on the dates. I have to filter data to not to include “Dec. And I want to select the "Nov" as the last month and count the volumes for last month which is in another table (Report1).

 

I used to solve this problem by adding a column with number in "Table1" in it as below:

Month#    Month    

1               Jul

2               Aug

3               Sep

4               Oct

5               Nov

6               Dec

 

And my other table named "Report1"

 

Report1:

Volume    Month    

4              Jul

3              Jul

2              Aug 

7              Aug

9              Aug

3              Sep

7              Oct

5              Oct

1              Nov

8              Nov

6              Dec

 

I use a measure to find the last month as:

 

LastMonth= VLOOKUP ('Table1'[Month], 'Table 1'[Month#], MAX('Table1'[Month#]))

 

Then use another measure as below:

TotalVolume= COUNTAX(FILTER('Report1','Report1'[Month]=[LastMonth]),'Report1'[Volume])

 

Measure "LastMonth" works fine itself. However, it is not working when referred in the second measure. 

I searched and see that VLOOKUP function returns a single value but do not know why its value is not working as a text value in another measure. 

 

I appreciate if you share your ideas to fix my problem. Thank you very much..

  • HI Ynew

     

    Please try this MEASURE

     

    TotalVolume =
    VAR mymonth = [LastMonth]
    RETURN
        COUNTAX ( FILTER ( 'Report1', 'Report1'[Month] = mymonth ), 'Report1'[Volume] )

     

     

11 Replies