March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
H2SO4 mg/l =
VAR H2SO4_apl =
CALCULATE (
SUMX ( ImportOfLIMS, ImportOfLIMS[H2SO4] ),
ImportOfLIMS[SAMPLE_GROUP_NAME] = "Acid Plant"
)
VAR isblankH2SO4 =
IF (
ISBLANK ( H2SO4_apl ),
SUMX ( WasteWaterapl_ambernet, WasteWaterAPL_ambernet[H2SO4 g/l Ambernet] ),
( H2SO4_apl )
)
VAR dgTOg =
DIVIDE ( ( isblankH2SO4 ), 10 )
RETURN
dgTOg
Solved! Go to Solution.
@Anonymous , that's interesting. Try adding some more debug code. I'm interested to see if the two methods you use to refer to [H2SO4 kg/d] give the same result.
VAR H2SO4measure = [H2SO4 kg/d]
VAR H2SO4column = CALCULATE ( SUMX ( ImportOfLIMS, 'ImportOfLIMS'[H2SO4 kg/d] ) )
VAR Bleed = [APL Bleed m3/day]
VAR H2SO4mg = [H2SO4 mg/l]
RETURN
FORMAT(MINX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & FORMAT(MAXX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & MINX(MostRecentDates, [@H2SO4])
& " ; " & MAXX(MostRecentDates, [@H2SO4])
& " ; " & FORMAT(Result, "0.00")
& " ; " & FORMAT(H2SO4measure, "0.00")
& " ; " & FORMAT(Bleed, "0.00")
& " ; " & FORMAT(H2SO4mg, "0.00")
If 'ImportOfLIMS'[H2SO4 kg/d] is actually a measure and not a column, then I believe you can change the [Avg_10_H2SO4_(kg/d)] to refer to it like this below. ADDCOLUMNS is an iterator and will calculate the expression for "@H2SO4" for every row in the AllDatesPrior table variable, so there is no need for a SUMX or CALCULATE.
VAR AllDates_H2SO4 =
ADDCOLUMNS (
AllDatesPrior,
//"@H2SO4", CALCULATE ( SUMX ( ImportOfLIMS, 'ImportOfLIMS'[H2SO4 kg/d] ) )
"@H2SO4", [H2SO4 kg/d]
)
Incidentally, from the raw data, what actually is the correct result for 21 Jun?
I changed the:
@Anonymous , it looks like your [H2SO4 kg/d] and [Avg_10_H2SO4_(kg/d)] measures in the column above are calculated slightly differently.
The [H2SO4 kg/d] measure is using data from [H2SO4 mg/l] * [APL Bleed m3/day],
but the [Avg_10_H2SO4_(kg/d)] measure is averaging the SUMX of the column 'ImportOfLIMS'[H2SO4 kg/d].
Are you sure this is exactly the same data?
Is 'ImportOfLIMS'[H2SO4 kg/d] a column in a source table, or it is the measure defined in your post?
To help look at what is being produced by the measure more closely, you could try replaceing the "RETURN NoBlanks" in your measure with this:
RETURN
FORMAT(MINX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & FORMAT(MAXX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & MINX(MostRecentDates, [@H2SO4])
& " ; " & MAXX(MostRecentDates, [@H2SO4])
& " ; " & FORMAT(Result, "0.00")
and this will give you some "debug" output to analyse.
Thanks for you comment. I followed your advice and the output for june 21st = minn 2595 and maxx also 2595
also you said that "the [Avg_10_H2SO4_(kg/d)] measure is averaging the SUMX of the column 'ImportOfLIMS'[H2SO4 kg/d]."
am I averaging the column or the row by row in the column? My intention was the 2nd.
@Anonymous , that's interesting. Try adding some more debug code. I'm interested to see if the two methods you use to refer to [H2SO4 kg/d] give the same result.
VAR H2SO4measure = [H2SO4 kg/d]
VAR H2SO4column = CALCULATE ( SUMX ( ImportOfLIMS, 'ImportOfLIMS'[H2SO4 kg/d] ) )
VAR Bleed = [APL Bleed m3/day]
VAR H2SO4mg = [H2SO4 mg/l]
RETURN
FORMAT(MINX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & FORMAT(MAXX(MostRecentDates, [Date]), "YYYYMMDD")
& " ; " & MINX(MostRecentDates, [@H2SO4])
& " ; " & MAXX(MostRecentDates, [@H2SO4])
& " ; " & FORMAT(Result, "0.00")
& " ; " & FORMAT(H2SO4measure, "0.00")
& " ; " & FORMAT(Bleed, "0.00")
& " ; " & FORMAT(H2SO4mg, "0.00")
If 'ImportOfLIMS'[H2SO4 kg/d] is actually a measure and not a column, then I believe you can change the [Avg_10_H2SO4_(kg/d)] to refer to it like this below. ADDCOLUMNS is an iterator and will calculate the expression for "@H2SO4" for every row in the AllDatesPrior table variable, so there is no need for a SUMX or CALCULATE.
VAR AllDates_H2SO4 =
ADDCOLUMNS (
AllDatesPrior,
//"@H2SO4", CALCULATE ( SUMX ( ImportOfLIMS, 'ImportOfLIMS'[H2SO4 kg/d] ) )
"@H2SO4", [H2SO4 kg/d]
)
Incidentally, from the raw data, what actually is the correct result for 21 Jun?
The correct result is 2471.
after applying the debug code I get:
your suggestion to edit out the sumx from the ADDCOLUMNS did the trick!
VAR AllDates_H2SO4 = ADDCOLUMNS ( AllDatesPrior, //"@H2SO4", CALCULATE ( SUMX ( ImportOfLIMS, 'ImportOfLIMS'[H2SO4 kg/d] ) ) "@H2SO4", [H2SO4 kg/d] )
after this I do get the right result: 2471.
I still don't really comprehend how that would matter and where the difference comes from. I feel like if I don't fully understand this i'l keep on making this same mistake in the future.
you said: "ADDCOLUMNS is an iterator and will calculate the expression for "@H2SO4" for every row in the AllDatesPrior table variable, so there is no need for a SUMX or CALCULATE."
I didn't know that ADDCOLUMNS automatically goes over every row just like SUMX. but does that explain the difference in value? if so, how exactly?
@Anonymous Glad it worked!
I'm not sure why the CALCULATE SUMX didn't work, either. The CALCULATE function is used to change the context of the expression, but in this case there were no changes to filters applied. The SUMX also is an iterator and changes the context, so a suspect the combination of ADDCOLUMNS, CALCULATE and SUMX together has ended up with a context that is different to expected.
To delve further you could add more debug code to examine what the CALCULATE-SUMX produces. For example, change it to each of these to check out what data it is producing.
CALCULATE ( MINX( ImportOfLIMS, 'ImportOfLIMS'[Date] ) )
CALCULATE ( MAXX( ImportOfLIMS, 'ImportOfLIMS'[Date] ) )
CALCULATE ( COUNTROWS( ImportOfLIMS))
CALCULATE ( MINX( ImportOfLIMS, 'Calendar'[Date] ) )
CALCULATE ( MAXX( ImportOfLIMS, 'Calendar'[Date] ) )
Yes, ADDCOLUMNS is an iterator function.
I will try and further debug this one soon. at leastnow I can continue building 😃
for now, thanks a lot for your help. appreciate it very much!
@Anonymous happy to help. Found this article which looks like it explains the issues in this case.
Context Transition and Expanded Tables - SQLBI
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
128 | |
90 | |
75 | |
56 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |