Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
samnaw
Resolver I
Resolver I

How to do Sum between

Hello:

 

I have 3 columns:

 

its looks like this:

r12from: 32021 means (MM-YYYY or 03-2021)

r12to: 22022 means (02-2022) 

samnaw_2-1668104286487.png

 

samnaw_0-1668102760308.png

samnaw_1-1668102807654.png

 

So I want to do something like this:

 

I have a "measure1" that spits out a date based on some calculation. measure1 is a date (i.e 13-Nov-21) 

SUM(Sales) all rows between 03-2021 and 02-2022 based on "measure1" 

 

So if measure1 is 13-Nov-21 so I want to SUM(Sales) all dates between 03-2021 and 02-2022. 

 

 

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

Hi @samnaw ,

 

Create new columns to transform the date.

r12from column= 
var _rightyear=RIGHT(('Table'[r12from]),4) 
var _leftmonth=LEFT(('Table'[r12from]),1) 
var _date=_rightyear&"/"&_leftmonth&"/"&1 
return _date

r12to column= 
var _rightyear=RIGHT(('Table'[r12to]),4) 
var _leftmonth=LEFT(('Table'[r12to]),1) 
var _date=_rightyear&"/"&_leftmonth&"/"&1 
return _date

Then create a measure like below:

measure =
VAR _1 =
    CALCULATE (
        SUM ( table[sales] ),
        FILTER (
            ALL ( table ),
            table[date] <= SELECTEDVALUE ( table[r12from column] )
&& table[date] >= SELECTEDVALUE ( table[r12to] )
        )
    )
RETURN
    IF ( measure1 = DATE ( 2021, 11, 21 ), _1, BLANK () )

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

1 REPLY 1
v-jayw-msft
Community Support
Community Support

Hi @samnaw ,

 

Create new columns to transform the date.

r12from column= 
var _rightyear=RIGHT(('Table'[r12from]),4) 
var _leftmonth=LEFT(('Table'[r12from]),1) 
var _date=_rightyear&"/"&_leftmonth&"/"&1 
return _date

r12to column= 
var _rightyear=RIGHT(('Table'[r12to]),4) 
var _leftmonth=LEFT(('Table'[r12to]),1) 
var _date=_rightyear&"/"&_leftmonth&"/"&1 
return _date

Then create a measure like below:

measure =
VAR _1 =
    CALCULATE (
        SUM ( table[sales] ),
        FILTER (
            ALL ( table ),
            table[date] <= SELECTEDVALUE ( table[r12from column] )
&& table[date] >= SELECTEDVALUE ( table[r12to] )
        )
    )
RETURN
    IF ( measure1 = DATE ( 2021, 11, 21 ), _1, BLANK () )

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.