0
votes

I am new to PowerBI and now trying to sum the values of each group at its own latest date by using Measure. I have tried to use "New Table" and Lookupvalue and it's success. However, I would like to use slicer for the date to sum the values as at that date.

Date Group Value
1/8  A   3
1/8  B   4
1/8  C   5
1/8  D   6
2/8  A   7
2/8  B   8
2/8  C   9 
4/8  A   10
4/8  B   11 
7/8  C   12
7/8  D   13

When the slicer is 7/8, value is A 10, B11, C12, D13, total = 46 When the slicer is 5/8, value is A10, B11, C9, D6, total = 36

I am using the measure as follows,

Measure = 
var _maxdate = 
CALCULATE(MAX(Sheet1[Date]),
            VALUES(Sheet1[Group]))
return
CALCULATE(SELECTEDVALUE(Sheet1[Value]),
            Sheet1[Date]=_maxdate)

It can show in visuals the last value of each group, but it can't sum them up. Can anyone help about that? Thanks a lot.

2
What is your expected output from the given sample data?mkRabbani

2 Answers

0
votes

You are almost there, your return value needs to be a SUM not the SELECTEDVALUE. You also need to clear the filter on date with the ALL function:

Measure = 
var _maxdate = 
CALCULATE(MAX(Sheet1[Date]),
            VALUES(Sheet1[Group]))
return
CALCULATE(SUM(Sheet1[Value]),
            ALL(Sheet1[Date]),
            Sheet1[Date] =_maxdate)
0
votes

I have figured it out myself and let me post it here. I am expecting the value of each group at its own latest date and sum those values.

First, use the measure as the above.

Measure = var _maxdate = CALCULATE(MAX(Sheet1[Date]), VALUES(Sheet1[Group])) return CALCULATE(SELECTEDVALUE(Sheet1[Value]), Sheet1[Date]=_maxdate)

Second, use the first measure and sum the total. Measure 2 = var _table = SUMMARIZE(Sheet1,Sheet1[Group], "_value", [Measure]) return SUMX(_table, [_value])