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
CJKPowerBI
Helper I
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:
 
TypeAmountDate
Balance$1626/30/2022
Balance$5696/30/2022
Balance$986/30/2022
Balance$5696/30/2022
Balance$986/30/2022
Balance$50,9136/30/2022
Balance$3,3216/30/2022
Balance$9,8036/30/2022
 $65,533

 

 
when i have this table it returns no value.... am i doing somehting wrong?
 
thank you
7 REPLIES 7
v-yadongf-msft
Community Support
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,

Yadong Fang

Ashish_Mathur
Super User
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
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
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])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

unfortunately @Greg_Deckler  this still returns no value... 

@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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@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?

 

TypeOwnerInv. TypeInstitutionAmountDate
BalanceOwner1Cash1$89,4856/30/2021
BalanceOwner1Cash1$7,1716/30/2021
BalanceOwner1Cash1$37612/31/2021
BalanceOwner1Cash1$1,98912/31/2021
BalanceOwner1Cash1$47312/31/2021
BalanceOwner1Cash1$1,98912/31/2021
BalanceOwner1Cash1$47312/31/2021
BalanceOwner1Cash1$118,02012/31/2021
BalanceOwner1Cash1$11,60712/31/2021
BalanceOwner1Cash1$1626/30/2022
BalanceOwner2Cash1$5696/30/2022
BalanceOwner2Cash1$986/30/2022
BalanceOwner2Cash1$5696/30/2022
BalanceOwner2Cash1$986/30/2022
BalanceOwner2Cash1$50,9136/30/2022
BalanceOwner2Cash1$3,3216/30/2022
BalanceOwner2Cash1$9,8036/30/2022

 

@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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.