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

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

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])

Follow on LinkedIn
@ 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.


Follow on LinkedIn
@ 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.


Follow on LinkedIn
@ 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
Europe Fabric Conference

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 Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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