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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
lauramatosv
Frequent Visitor

SUM until a given date

Hey, everyone! 

 

It seems to be simple, but somehow I can't get through it! So, I hope you can kindly help me 🙂 

 

I have a table in Excel which I'd like reproduce in PBI:

lauramatosv_0-1610035270491.png

Basically, I have to sum my values until this date in the table header (it's the day I get the data) and show the sum value in this day. 

 

In PowerBI, all I could do so far was the following table with the measure:

 

.#IncomeByMonth = CALCULATE(SUM(Received[VALREC]), 'Chart Account'[Income]="Sim", 'Report'[Year]=2020) 

lauramatosv_1-1610035518003.png

 

The following measure gives me the same exact result showed above: 

.#IncomeByMonth = CALCULATE(SUM(Received[VALREC]), 'Chart Account'[Income]="Sim", 'Report'[Year]=2020), FILTER(ALL('Report date'[date]), 'Report date'[date]<=MAX('Report date'[date])))

 

I use a table containing a single column with the dates I downloaded the repport, so I don't really rely on a calendar table (I know it is a sin)

 

I do know I'm missing some FILTER function here, I've tried so many things and it didn't work (even CLOSINGBALANCEMONTH, which I don't really think it applies here)

I was so easy on Excel, I could just use SUMIF and then compare to any date reference, but I can't do it in PBI. 

Any insights? 

 

Thank you all in advance 🙂 

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @lauramatosv ,

 

Please try this.

.#IncomeByMonth = 
VAR x = 
CALCULATE(
    SUM(Received[VALREC]), 
    FILTER(
        ALL('Report date'[date]), 
        'Report date'[date]<=MAX('Report date'[date])
    )
)
RETURN
CALCULATE(
    x,
    FILTER(
        'Chart Account',
        'Chart Account'[Income]="Sim"
    ),
    FILTER(
        'Report',
        'Report'[Year]=2020
    )
)

If it's invalid, please provide a sample file of .pbix, I need to determine the filter context in the formula according to the data model.

 

Best regards,
Lionel Chen

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

edhans
Super User
Super User

You can try this. The MAX value you were using was calculating each time. I moved it to a variable, which is equivalent to wrapping in EARLIER, but a better practice.

 

IncomeByMonth =
VAR varReportDate =
    MAX( 'Report date'[date] )
RETURN
    CALCULATE(
        SUM( Received[VALREC] ),
        'Chart Account'[Income] = "Sim",
        'Report'[Year] = 2020,
        FILTER(
            ALL( 'Report date'[date] ),
            'Report date'[date] <= varReportDate
        )
    )

But to really help, we need data we can use. Cannot use screenshots for data. Help us help you.
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
PaulDBrown
Community Champion
Community Champion

@lauramatosv 

How do you define the cutoff date?

A simple way of doing this is to use a measure along the lines of:

Cutoff =
VAR CutOffDate = [whatever expression you use to define the cutoff date]
RETURN
IF(SELECETEDVALUE('Report date'[date]) > CutOffDate, BLANK(), [Your measure])

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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