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
techvidya
Frequent Visitor

sum of amounts from start date to selected date

Hey guys,

 

Hope you are well and safe in this pandemic. Below is my requirment , for which iam expecting a expert solution.

 

I have Table A which has Project start date column and Table B which holds the Revenue for Each month(Month & Revenue columns)

 

Now, if i select any month in slicer(calender table), i should get the revenue from project start date to selected month in slicer.

 

For ex: if Project start date is April 2020 and i select june in slicer, i should get sum of Revenue from April,may,june.

if April Month Revenue is 5000

May is 2000

June is 3000

 

So on selecting june month in slicer, i should get revenue as 10000,

if i select may in slicer, i should get revenue as 7000

 

TIA

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

Hi @techvidya 

Due to I don't know your data model, I build TableA and TableB to have a test.

TableA add Year column and Month column by calculated column.

Year = YEAR('Table A'[Project start date])
Month = MONTH('Table A'[Project start date])

1.png

TableB:

2.png

Build a Calendar Table.

Calendar = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]))

Here I build a Measure to get the sum of revenues between start month and select month in the same year as start date.

Measure =
VAR _selected =
    SELECTEDVALUE ( 'Calendar'[Month] )
RETURN
    SUMX (
        FILTER (
            'Table B',
            'Table B'[Month] <= _selected
                && 'Table B'[Year] = MAX ( 'Table A'[Year] )
                && 'Table B'[Month] >= MAX ( 'Table A'[Month] )
        ),
        'Table B'[Revenue]
    )

Result is as below.

Default:

3.png

Select May in Slicer, Project A will show Sum of Revenue from 2020/4 to 2020/5,C will show Sum of Revenue from 2019/4 to 2019/5.

4.png

You can download the pbix file from this link: sum of amounts from start date to selected date

If this reply still couldn't help you solve your problem, please show me the data model about TableA and TableB.

OR you can share your pbix file with me by your Onedrive for Business.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

View solution in original post

6 REPLIES 6
v-rzhou-msft
Community Support
Community Support

Hi @techvidya 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

v-rzhou-msft
Community Support
Community Support

Hi @techvidya 

Due to I don't know your data model, I build TableA and TableB to have a test.

TableA add Year column and Month column by calculated column.

Year = YEAR('Table A'[Project start date])
Month = MONTH('Table A'[Project start date])

1.png

TableB:

2.png

Build a Calendar Table.

Calendar = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]))

Here I build a Measure to get the sum of revenues between start month and select month in the same year as start date.

Measure =
VAR _selected =
    SELECTEDVALUE ( 'Calendar'[Month] )
RETURN
    SUMX (
        FILTER (
            'Table B',
            'Table B'[Month] <= _selected
                && 'Table B'[Year] = MAX ( 'Table A'[Year] )
                && 'Table B'[Month] >= MAX ( 'Table A'[Month] )
        ),
        'Table B'[Revenue]
    )

Result is as below.

Default:

3.png

Select May in Slicer, Project A will show Sum of Revenue from 2020/4 to 2020/5,C will show Sum of Revenue from 2019/4 to 2019/5.

4.png

You can download the pbix file from this link: sum of amounts from start date to selected date

If this reply still couldn't help you solve your problem, please show me the data model about TableA and TableB.

OR you can share your pbix file with me by your Onedrive for Business.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

amitchandak
Super User
Super User

@techvidya , do you have revenue before project start date if not this will work

 

measure =
var _max = maxx(allselected(Date),Date[Date])
return
calculate(Sum(TableB[revenue]), filter(TableB, TableB[Date] <_max ))

 

Assume you have date in table B

 

or

 

measure =
var _max = maxx(allselected(Date),Date[Date])
return
calculate(Sum(TableB[revenue]),Values(TableA[Project]),filter(TableB, TableB[Date] <_max && TableA >=max(projectA[startDate])))

 

measure =
var _max = maxx(allselected(Date),Date[Date])
return
calculate(SumX(Values(TableA[Project]), TableB[revenue]), filter(TableB, TableB[Date] <_max && TableA >=max(projectA[startDate])))

@amitchandak , can you pls be more precise on this

 

measure =
var _max = maxx(allselected(Date),Date[Date])
return
calculate(Sum(TableB[revenue]),Values(TableA[Project]),filter(TableB, TableB[Date] <_max && TableA >=max(projectA[startDate])))

 

 

@techvidya , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

@amitchandak ,

I will have the revenue before project date also, but it will be for another year.

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.