DAX code change from calculated column to a measureCreating DAX peer measureCreate a Running Total Measure in DAX from another Measure (not Calculated Column)How to refer to a single value in a Calculated Column in a measure (DAX)Condition with multiple columns in DAXMeasure in DAX to calculate YTD for chosen month only for Power BIMax partition by DAX measure equivalent?Power BI - DAX measure to calculate sales first 31 days - 'DATEADD' expects a contiguous selectionAverage of a DAX measure Power BIHow to calculate the MAX from a Dax Measure (Excel)DAX calculated column does not work in a measure calculation
How often should alkaline batteries be checked when they are in a device?
Chemistry Riddle
What kind of anatomy does a centaur have?
Was US film used in Luna 3?
Wiring IKEA light fixture into old fixture
Dedicated to our #1 Fan
The seven story archetypes. Are they truly all of them?
What rules turn any attack that hits a given target into a critical hit?
Impact of throwing away fruit waste on a peak > 3200 m above a glacier
Found more old paper shares from broken up companies
High income and difficulty during interviews
Were Moshe's sons Jewish?
How can I print a 1 cm overhang with minimal supports?
How can I calculate the cost of Skyss bus tickets
Is it possible to access the complete command line including pipes in a bash script?
Why is the UH-60 tail rotor canted?
Ultraproduct of Dividing Lines
Does Impedance Matching Imply any Practical RF Transmitter Must Waste >=50% of Energy?
How to Sow[] until I've Reap[]'d enough?
Import data from a current web session?
Is there a way to shorten this while condition?
Killing a star safely
Short story where a flexible reality hardens to an unchanging one
Why did computer video outputs go from digital to analog, then back to digital?
DAX code change from calculated column to a measure
Creating DAX peer measureCreate a Running Total Measure in DAX from another Measure (not Calculated Column)How to refer to a single value in a Calculated Column in a measure (DAX)Condition with multiple columns in DAXMeasure in DAX to calculate YTD for chosen month only for Power BIMax partition by DAX measure equivalent?Power BI - DAX measure to calculate sales first 31 days - 'DATEADD' expects a contiguous selectionAverage of a DAX measure Power BIHow to calculate the MAX from a Dax Measure (Excel)DAX calculated column does not work in a measure calculation
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a fact table with settlement_date, product_id, service_id, location_id, and ticket_id and srv_adjusted_earning columns.
I have determined the DAX query to generate a calculated column that sums the srv_adjusted_earning column over the date range: settlement date and settlement date - 27 days (i.e. a 4 week window) as:
=CALCULATE(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
FILTER(factService, factService[PRO_ID] = EARLIER(factService[PRO_ID])),
FILTER(factService, factService[SER_ID] = EARLIER(factService[SER_ID])),
FILTER(factService, factService[LOC_ID_SELLING] =
EARLIER(factService[LOC_ID_SELLING])),
FILTER(factService, factService[TIS_ID] = EARLIER(factService[TIS_ID]))
)
I am trying to convert this DAX calculated column to a measure and I tried the following:
blob:=CALCULATE
(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
ALLEXCEPT(factService, factService[PRO_ID]),
ALLEXCEPT(factService, factService[SER_ID]),
ALLEXCEPT(factService, factService[LOC_ID_SELLING]),
ALLEXCEPT(factService, factService[TIS_ID])
)
But I get:
Error: Calculation error in measure 'factService'[blob]: A single value for column 'SETTLEMENT_DATE' in table 'factService' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
Anybody know how I fix this?
dax calculated-columns measure
add a comment |
I have a fact table with settlement_date, product_id, service_id, location_id, and ticket_id and srv_adjusted_earning columns.
I have determined the DAX query to generate a calculated column that sums the srv_adjusted_earning column over the date range: settlement date and settlement date - 27 days (i.e. a 4 week window) as:
=CALCULATE(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
FILTER(factService, factService[PRO_ID] = EARLIER(factService[PRO_ID])),
FILTER(factService, factService[SER_ID] = EARLIER(factService[SER_ID])),
FILTER(factService, factService[LOC_ID_SELLING] =
EARLIER(factService[LOC_ID_SELLING])),
FILTER(factService, factService[TIS_ID] = EARLIER(factService[TIS_ID]))
)
I am trying to convert this DAX calculated column to a measure and I tried the following:
blob:=CALCULATE
(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
ALLEXCEPT(factService, factService[PRO_ID]),
ALLEXCEPT(factService, factService[SER_ID]),
ALLEXCEPT(factService, factService[LOC_ID_SELLING]),
ALLEXCEPT(factService, factService[TIS_ID])
)
But I get:
Error: Calculation error in measure 'factService'[blob]: A single value for column 'SETTLEMENT_DATE' in table 'factService' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
Anybody know how I fix this?
dax calculated-columns measure
add a comment |
I have a fact table with settlement_date, product_id, service_id, location_id, and ticket_id and srv_adjusted_earning columns.
I have determined the DAX query to generate a calculated column that sums the srv_adjusted_earning column over the date range: settlement date and settlement date - 27 days (i.e. a 4 week window) as:
=CALCULATE(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
FILTER(factService, factService[PRO_ID] = EARLIER(factService[PRO_ID])),
FILTER(factService, factService[SER_ID] = EARLIER(factService[SER_ID])),
FILTER(factService, factService[LOC_ID_SELLING] =
EARLIER(factService[LOC_ID_SELLING])),
FILTER(factService, factService[TIS_ID] = EARLIER(factService[TIS_ID]))
)
I am trying to convert this DAX calculated column to a measure and I tried the following:
blob:=CALCULATE
(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
ALLEXCEPT(factService, factService[PRO_ID]),
ALLEXCEPT(factService, factService[SER_ID]),
ALLEXCEPT(factService, factService[LOC_ID_SELLING]),
ALLEXCEPT(factService, factService[TIS_ID])
)
But I get:
Error: Calculation error in measure 'factService'[blob]: A single value for column 'SETTLEMENT_DATE' in table 'factService' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
Anybody know how I fix this?
dax calculated-columns measure
I have a fact table with settlement_date, product_id, service_id, location_id, and ticket_id and srv_adjusted_earning columns.
I have determined the DAX query to generate a calculated column that sums the srv_adjusted_earning column over the date range: settlement date and settlement date - 27 days (i.e. a 4 week window) as:
=CALCULATE(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
FILTER(factService, factService[PRO_ID] = EARLIER(factService[PRO_ID])),
FILTER(factService, factService[SER_ID] = EARLIER(factService[SER_ID])),
FILTER(factService, factService[LOC_ID_SELLING] =
EARLIER(factService[LOC_ID_SELLING])),
FILTER(factService, factService[TIS_ID] = EARLIER(factService[TIS_ID]))
)
I am trying to convert this DAX calculated column to a measure and I tried the following:
blob:=CALCULATE
(
SUM(factService[SRV_ADJUSTED_EARNING]),
DATESBETWEEN
(
factService[SETTLEMENT_DATE],
DATEADD(factService[SETTLEMENT_DATE], -27, DAY),
factService[SETTLEMENT_DATE]
),
ALLEXCEPT(factService, factService[PRO_ID]),
ALLEXCEPT(factService, factService[SER_ID]),
ALLEXCEPT(factService, factService[LOC_ID_SELLING]),
ALLEXCEPT(factService, factService[TIS_ID])
)
But I get:
Error: Calculation error in measure 'factService'[blob]: A single value for column 'SETTLEMENT_DATE' in table 'factService' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
Anybody know how I fix this?
dax calculated-columns measure
dax calculated-columns measure
edited Mar 26 at 14:43
Stuart5069
asked Mar 26 at 14:37
Stuart5069Stuart5069
103 bronze badges
103 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
As the error mentions, the issue is with factService[SETTLEMENT_DATE]
. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgotDATEADD
needs a date column as the first argument. As far as theMAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.
– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359816%2fdax-code-change-from-calculated-column-to-a-measure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As the error mentions, the issue is with factService[SETTLEMENT_DATE]
. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgotDATEADD
needs a date column as the first argument. As far as theMAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.
– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
add a comment |
As the error mentions, the issue is with factService[SETTLEMENT_DATE]
. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgotDATEADD
needs a date column as the first argument. As far as theMAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.
– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
add a comment |
As the error mentions, the issue is with factService[SETTLEMENT_DATE]
. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
As the error mentions, the issue is with factService[SETTLEMENT_DATE]
. In the measure, there is no row context so that it knows which date you are talking about, so you need to specify it somehow. I'd suggest using a variable along these lines:
blob :=
VAR SettleDate = MAX ( factService[SETTLEMENT_DATE] )
RETURN
CALCULATE (
SUM ( factService[SRV_ADJUSTED_EARNING] ),
DATESBETWEEN (
factService[SETTLEMENT_DATE],
SettleDate - 27,
SettleDate
),
ALLEXCEPT (
factService,
factService[PRO_ID],
factService[SER_ID],
factService[LOC_ID_SELLING],
factService[TIS_ID]
)
)
Here the variable picks the maximal settlement date in the current filter context. If that's not exactly what you need, adjust the definition accordingly.
edited Mar 26 at 18:34
answered Mar 26 at 14:51
Alexis OlsonAlexis Olson
18.2k2 gold badges22 silver badges38 bronze badges
18.2k2 gold badges22 silver badges38 bronze badges
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgotDATEADD
needs a date column as the first argument. As far as theMAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.
– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
add a comment |
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgotDATEADD
needs a date column as the first argument. As far as theMAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.
– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Thanks for your response. That throws the error: "Semantic error: the first argument to "DATEADD" must specify a column. Also I am looking to take the dates 28 relative to the date in the row, so given Feb 28th that would be 1st to 28th Feb inclusive. Wouldn't the MAX take the largest date in the fact?
– Stuart5069
Mar 26 at 16:32
Ah, I forgot
DATEADD
needs a date column as the first argument. As far as the MAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.– Alexis Olson
Mar 26 at 18:34
Ah, I forgot
DATEADD
needs a date column as the first argument. As far as the MAX
goes, it takes the max in the current filter context, not necessarily over the whole fact table. Try my edit.– Alexis Olson
Mar 26 at 18:34
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
Thanks again for the quick response. That solves the semantic error and you are correct that the MAX is in the filter context. I have created the calculated field and compared to the calculated column and the answers are the same, and I have marked your post as the correct answer. I trawled the net and the Russo/Ferrari book for an answer without joy so I cannot thank you enough for your post. Nice trick to use the variable to force the filter context - I won't forget that one.
– Stuart5069
Mar 27 at 9:59
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359816%2fdax-code-change-from-calculated-column-to-a-measure%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown