cancel
Showing results for
Did you mean:

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Helper I

## Sum of columns based on latest date

Hello all,

i have the below measure:

"Sum Balance Current Year = Var Max_Date = MAX('Table'[Date])
Var Latest_Value = CALCULATE(SUM('Table'[Amount]),'Table'[Date]=Max_Date,'Table'[Type]="Balance")
return Latest_Value "

and the data table is below:

 Type Amount Date Balance \$162 6/30/2022 Balance \$569 6/30/2022 Balance \$98 6/30/2022 Balance \$569 6/30/2022 Balance \$98 6/30/2022 Balance \$50,913 6/30/2022 Balance \$3,321 6/30/2022 Balance \$9,803 6/30/2022 \$65,533

when i have this table it returns no value.... am i doing somehting wrong?

thank you
7 REPLIES 7
Community Support

Hi @CJKPowerBI ,

Has your problem been solved? If solved, please consider Accept it as the solution to help the other members find it more quickly.

Best regards,

Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  Write these measures

Bal = SUM('Table'[Amount])

Farthest date = max('Table'[Date])

Bal latest = calculate([Bal],datesbetween(calendar[date],[Farthest date],[Farthest date]),'Table'[Type]="Balance")

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

@CJKPowerBI Try:

``````Measure =
VAR __Max_Date = MAX('Table'[Date])
VAR __Table = FILTER(ALLSELECTED('Table'),[Date] = __Max_Date && [Type] = "Balance")
RETURN
SUMX(__Table, [Amount])``````

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

unfortunately @Greg_Deckler  this still returns no value...

Super User

@CJKPowerBI It is quite likely that you are unintentionally withholding critical information. Please see the PBIX attached below signature. You want Table 4 and Measure 4 in that table. Works.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

@Greg_Deckler thank you for sending the .pbix but still didnt work with my data... indeed i have more columns which are not in the measure but maybe they create the issue...

my data is in an excel and as below if i have no filters at all so based on the measure it should show the sum of all column Amount correct?

 Type Owner Inv. Type Institution Amount Date Balance Owner1 Cash 1 \$89,485 6/30/2021 Balance Owner1 Cash 1 \$7,171 6/30/2021 Balance Owner1 Cash 1 \$376 12/31/2021 Balance Owner1 Cash 1 \$1,989 12/31/2021 Balance Owner1 Cash 1 \$473 12/31/2021 Balance Owner1 Cash 1 \$1,989 12/31/2021 Balance Owner1 Cash 1 \$473 12/31/2021 Balance Owner1 Cash 1 \$118,020 12/31/2021 Balance Owner1 Cash 1 \$11,607 12/31/2021 Balance Owner1 Cash 1 \$162 6/30/2022 Balance Owner2 Cash 1 \$569 6/30/2022 Balance Owner2 Cash 1 \$98 6/30/2022 Balance Owner2 Cash 1 \$569 6/30/2022 Balance Owner2 Cash 1 \$98 6/30/2022 Balance Owner2 Cash 1 \$50,913 6/30/2022 Balance Owner2 Cash 1 \$3,321 6/30/2022 Balance Owner2 Cash 1 \$9,803 6/30/2022

Super User

@CJKPowerBI Here is an updated PBIX (below signature) with an your new sample data. As you ucan see in the Card visual you get the correct value \$65,533. I also added a Measure 5 so that you can see exactly which rows are being included in that calculation (not all rows, just rows with the most recent date as you originally specified. Is the problem that you aren't getting the \$65,533 number in some other visualization that you have? Perhaps this version will work for you although I would really need to know the visualization being used and its configuration:

``````Measure 6 =
VAR __Max_Date = MAXX(ALL('Table4'),[Date])
VAR __Table = FILTER(ALL('Table4'),[Date] = __Max_Date && [Type] = "Balance")
RETURN
SUMX(__Table, [Amount])``````

You can see how the two measures work differently in the Table visual.

Finally, just from your description, I wonder if perhaps you are running afoul of AutoExist where you are filtering on two or more columns in the same table and autoexist is removing all of the rows it doesn't think should be calculated.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors