Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
gitguto
Contributor III
Contributor III

Last value of a dimension as a condition

Hey folks,

I have three columns "Version", "Units sold" and "Date". I need to find an expression that is able to:

sum(units sold in 2021 from the historical version + units sold in 2021 from the latest version available).

I can't find a solution because the version name changes every week from w1 to w2, w3... and they don't have fixed starting dates associated with them. (Ex. w01 doesn't necessarily starts from 1/1/2021, w2 doesn't necessarily starts from 1/8/2021, etc)

Example

VERSIONUNITS SOLDDate
HISTORICAL1012/1/2020
HISTORICAL201/1/2021
w01101/1/2021
w0151/1/2021
w02151/1/2021
w02151/8/2021
w05301/15/2021

 

Expected output = 20 + 30 = 50

 

I tried MaxString, but it returns "HISTORICAL" instead of the latest W#

Sum({<VERSION = {'$(=Maxstring([VERSION]))'} , Date = {">=$(=YearStart(max(Date)))"}>} [Units Sold]) +
Sum({<VERSION = {'HISTORICAL'} ,  Date = {">=$(=YearStart(max(Date)))"}>} [Units Sold])

 

P.S. I'm writing this expression in the "Edit Expression" field inside a bar chart  ->Data - Measure(Length of bars)

Labels (4)
2 Solutions

Accepted Solutions
salonicdk28
Creator II
Creator II

Please try this-

Instead of single quote, try with double quotes as mine is working , refer below-

=sum({<VERSION={"$(=MaxString(VERSION))"},Date={">=$(=Yearstart(max(Date)))"}>}[UNITS SOLD])+
sum({<VERSION={'HISTORICAL'},Date={">=$(=Yearstart(max(Date)))"}>}[UNITS SOLD])

View solution in original post

gitguto
Contributor III
Contributor III
Author

Nevermind, I got it! 

 

Sum({<VERSION = {'HISTORICAL'} , Date = {"*2021*"}>} [Parts and Accessories])
+Sum({<VERSION={"$(=MaxString(VERSION))"}, Date = {"*2021*"}>} [Parts and Accessories])

View solution in original post

5 Replies
Saravanan_Desingh

Try this,

=Sum({<VERSION = {'HISTORICAL'}, Date = {">=$(=YearStart(max(Date)))"}>} [UNITS SOLD])
=Sum({<VERSION = {"w*"}, Date={">=$(=max(Date))"}>} [UNITS SOLD])

commQV18.PNG

gitguto
Contributor III
Contributor III
Author

Thanks for the reply,

Unfortunately this does not work because I need to sum all the values from the latest version from 2021, not only the entry with the maximum Date.

I'll give you another example:

gitguto_0-1614264273477.png

In this case, my expected output would be 20 + 10 + 25 + 30 = 85. That is (20 +10 = (all units sold in 2021 from the historical version) + 25 +30 = (all units sold in 2021 from the latest version available, in this example it would be w04)

salonicdk28
Creator II
Creator II

Please try this-

Instead of single quote, try with double quotes as mine is working , refer below-

=sum({<VERSION={"$(=MaxString(VERSION))"},Date={">=$(=Yearstart(max(Date)))"}>}[UNITS SOLD])+
sum({<VERSION={'HISTORICAL'},Date={">=$(=Yearstart(max(Date)))"}>}[UNITS SOLD])

gitguto
Contributor III
Contributor III
Author

Thank you!! It works!!

In the same thread, would you know how to fix the Year to 2021? I'm afraid this Yearstart(max(Date)) condition will fail eventually when I start getting data from 2022. I tried something like:

 

Date={"$(=Year(Date) = 2021))"} but it returns 0

gitguto
Contributor III
Contributor III
Author

Nevermind, I got it! 

 

Sum({<VERSION = {'HISTORICAL'} , Date = {"*2021*"}>} [Parts and Accessories])
+Sum({<VERSION={"$(=MaxString(VERSION))"}, Date = {"*2021*"}>} [Parts and Accessories])