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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mic_rys_eLbiz
Regular Visitor

Sum of the continuous values by week

Hi All, 

I have a problem with the measure  creation and I'm looking for the DAX  hero 🙂

My measure (meas2) fills last value of the other measure (meas1) for the empty cusomers periods. For example:

mic_rys_eLbiz_0-1648026556615.png

My goal is to sum up Meas2 for the weeks:

mic_rys_eLbiz_1-1648026698199.png

I tried in different ways, using summarize etc but I can't find the solution 😞


Measures code;

step 1 =

VAR MaxDate =MAX ( 'Date'[Date] )

RETURN

CALCULATE ( [Meas1],

FILTER ( 'Date', 'Date'[Date] = MaxDate )

)

---------------------------------------------------

Meas2=
VAR PrevDate =
MAXX (
FILTER (
ALL('Date') ,
'Date'[Date] < MAX ( 'Date'[Date])
&& NOT ( ISBLANK ( [step 1] ) )
),
'Date'[Date]
)
VAR LastValueFill =
CALCULATE (
[Meas1],
FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] = PrevDate )
)
VAR FillEmpty = if( ISBLANK([step 1]), LastValueFill,[step 1] )

return
FillEmpty

-----------------------------------------

As you can see it doesn't work when I would like to sum up by weeks:

mic_rys_eLbiz_3-1648027466332.png

 

I tried sth like this:

Meas3 =

var _crosstable = CALCULATETABLE(CROSSJOIN(Clients,'Date'))
var _client_week = SUMMARIZE(_crosstable,'Date'[Week],Clients[Code])
var _finalresult = SUMX(_client_week,
[Meas 2]
)
return
if(
and(HASONEFILTER(Clients[Code]),HASONEFILTER('Date'[Week]))
,[Meas 2]
, _finalresult
)
----------
But It doesn't work (total is ok but per week is wrong)

mic_rys_eLbiz_4-1648027600918.png

I can't add a sample because it's live connected to AS, part of the model:

mic_rys_eLbiz_5-1648027720182.png

So Dax Heroes, please help me! 😞

 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

I was able to get the below code working by changing the relationship between Clients and VisitTargets from bi-directional to single

Sum of meas 2 = 
SUMX( VALUES(Clients[Code]), CALCULATE([Meas 2]))

I don't know if changing that is an option for you but it might make things simpler. Trying to follow filters across multiple bi-directional relationships is a nightmare.

View solution in original post

15 REPLIES 15
johnt75
Super User
Super User

I was able to get the below code working by changing the relationship between Clients and VisitTargets from bi-directional to single

Sum of meas 2 = 
SUMX( VALUES(Clients[Code]), CALCULATE([Meas 2]))

I don't know if changing that is an option for you but it might make things simpler. Trying to follow filters across multiple bi-directional relationships is a nightmare.

@johnt75 you are the Guy! I modyfied a little for bi-directional:
 

SUMX( CALCULATETABLE( VALUES(Clients[Code]),CROSSFILTER(Clients[Code],VisitTargets[Code],OneWay)),
CALCULATE(
[Meas 2]
)
 
and I think it works fine! Thank a lot!
mic_rys_eLbiz
Regular Visitor

Guys @amitchandak @johnt75 , I prepared sample in the pbix file, I'm counting on you ! 🙂
https://files.fm/u/6a9z36cm4

johnt75
Super User
Super User

I think you're right to use the SUMX over SUMMARIZE but the code isn't quite right. Use Performance Analyzer to get the DAX code which is generated for the table where you have Code, Week and Meas2. That will use SUMMARIZECOLUMNS but hopefully you can translate that into ADDCOLUMNS .. SUMMARIZE to produce the same table. You can then do a SUMX over that.

the part of the code is:

 

VAR __DS0FilterTable =
TREATAS({"7016479",
"7016828"}, 'Clients'[Code])

VAR __DS0Core =
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(ROLLUPGROUP('Clients'[Code], 'Date'[Week]), "IsGrandTotalRowTotal"),
__DS0FilterTable,
"Meas2", 'ExternalData'[Meas2]
)

could you help me?

 

Try

Meas 3 =
SUMX( ADDCOLUMNS( SUMMARIZE( 'Clients', 'Clients'[Code], 'Date'[Week]),
   "@value", [Meas 2] ),
   [@value]
)

I can't use summarize because "code" and "week" are not in the table clients, I tried sth like this but I can't use "weekk" from combinetable1 

mic_rys_eLbiz_0-1648034544105.png

my hands down 😕

Maybe something using GENERATE, like

Meas 3 =
var summaryTable = GENERATE( VALUES( 'Clients'[Code]),
   ADDCOLUMNS( VALUES('Date'[Week]), "@value", CALCULATE( [Meas 2] ) )
)
return SUMX( summaryTable, [@value] )

Doesn't work..

mic_rys_eLbiz_0-1648036796065.png

Maybe I need to do some modification in the [Meas2] because it cuts values which don't exists but are artificial filled by [Meas2] ?

 

What is funny that if I tried to sum up by Code my measure works:

Meas3 =

var _crosstable = CALCULATETABLE(CROSSJOIN(Clients,'Date'))
var _client_week = SUMMARIZE(_crosstable,'Date'[Week],Clients[Code])
var _finalresult = SUMX(_client_week,
[Meas 2]
)
return
if(
and(HASONEFILTER(Clients[Code]),HASONEFILTER('Date'[Week]))
,[Meas 2]
, _finalresult
)

 

mic_rys_eLbiz_1-1648037146679.png

 

 

 

In my GENERATE code try changing VALUES( Clients[Code]) to ALL( Clients[Code])

still not working 😞

mic_rys_eLbiz_1-1648038857586.png

 

amitchandak
Super User
Super User

@mic_rys_eLbiz , to me meas3 looks like

Sumx(filter(allselected(Table), Table[Week] = max(Table[Week])), [Meas2])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

unfortunatelly not:(

mic_rys_eLbiz_0-1648031260015.png

 

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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak ok, I try to prepare pbix file for this case

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.