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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Anonymous
Not applicable

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors