addcolumns
10 TopicsError with VALUES Function When No Filter is Applied and Issue with ADDCOLUMNS in DAX Measure
I'm trying to create a DAX measure that calculates reliability, but I’m encountering an issue. The goal is to make the measure work when one or more equipment items are selected. However, when no equipment filter is applied, it throws an error in the graph. I need help adapting the formula to handle this case properly. Here’s the original code: Confiabilidade_Sistema = VAR t = SELECTEDVALUE(Tabela_TTF[TTF]) -- Time to failure (in hours) VAR Equipamentos = VALUES(TTF[Equipamento Corrigido]) VAR Confiabilidades = ADDCOLUMNS( Equipamentos, "Confiabilidade", VAR Beta = CALCULATE([b_eq], TTF[Equipamento Corrigido] = EARLIER(TTF[Equipamento Corrigido])) VAR Eta = CALCULATE(EXP(-[a_eq] / Beta), TTF[Equipamento Corrigido] = EARLIER(TTF[Equipamento Corrigido])) RETURN IF(NOT(ISBLANK(Beta)) && NOT(ISBLANK(Eta)), EXP(-POWER(t / Eta, Beta)), 1) ) RETURN 1 - PRODUCTX(Confiabilidades, 1 - [Confiabilidade]) Now, I’m trying to adapt the formula to handle both cases — when equipment is filtered and when no filter is applied: Confiabilidade_Sistema = VAR t = SELECTEDVALUE(Tabela_TTF[TTF]) -- Time to failure (in hours) VAR Equipamentos = IF( ISFILTERED(TTF[Equipamento Corrigido]), VALUES(TTF[Equipamento Corrigido]), FILTER( VALUES(TTF[Equipamento Corrigido]), NOT(ISBLANK(TTF[a_eq])) ) ) VAR Confiabilidades = ADDCOLUMNS( Equipamentos, "Confiabilidade", VAR Beta = CALCULATE([b_eq], TTF[Equipamento Corrigido] = EARLIER(TTF[Equipamento Corrigido])) VAR Eta = CALCULATE(EXP(-[a_eq] / Beta), TTF[Equipamento Corrigido] = EARLIER(TTF[Equipamento Corrigido])) RETURN IF(NOT(ISBLANK(Beta)) && NOT(ISBLANK(Eta)), EXP(-POWER(t / Eta, Beta)), 1) ) RETURN 1 - PRODUCTX(Confiabilidades, 1 - [Confiabilidade]) -- Calculates system reliability However, it returns the following error: "The ADDCOLUMNS function expected a table expression for the '' argument, but a string or numeric expression was used." The issue arises when no equipment is selected. If any equipment is selected, the graph works fine. Could you help me fix this issue?Solved727Views1like2CommentsCalculated table with additional calculated column
Dear Group, I would like to create a table that will be based on Union as below: Ranking = Var _Plant1 = CALCULATETABLE(SUMMARIZE('For Plants','For Plants'[Customer],'For Plants'[Plant abb],"Sum of act",sum('For Plants'[Actuals in LC])),FILTER('For Plants','For Plants'[Plant abb]="Plant1")) var _summary = ADDCOLUMNS(_Plant1,"Rank",RANKX(ALL(_Plant1),_Plant1[Sum of act],,DESC,Dense)) Var _Plant2 = CALCULATETABLE(SUMMARIZE('For Plants','For Plants'[Customer],'For Plants'[Plant abb],"Sum of act",sum('For Plants'[Actuals in LC])),FILTER('For Plants','For Plants'[Plant abb]="Plant2")) var _summary2 = ADDCOLUMNS(_Plant2,"Rank",RANKX(ALL(_Plant2),_Plant2[Sum of act],,DESC,Dense)) RETURN union(_summary,_summary2) Unfortunately, this doesn't work. It works if I do it step by step - first create a separate table per plant, then add a column with ranking and then create a separate table with UNION, but as I have 10 plants, I would like to avoid creation of 11 tables. The overall idea is to give rank to per customer per plant based on sum of actuals. Could you please advise how to do it all at one? Thank you in advance.Solved729Views0likes2CommentsHelp with calendar
Hi, I have a baffling issue creating column Month (see the screenshot) where the date column will change to the next month. Without adding column Month - table values are correct Add Month column - the date column is wrong Any hints are appreciated. Thanks.Solved872Views0likes4CommentsHow to rewrite summarize with addcolumns for my scenario
Using summarize is not best practice. Best practices using SUMMARIZE and ADDCOLUMNS The code below works both in daxstudio and in my dataset. The child table MBPL gets a new column added call CheckPoint Next. Great. But reading the above article using summarize is not good. So how to refactor the below? --CheckPoint Next = -- uncomment for pbi desktop EVALUATE -- comment out for pbi desktop but needed for daxstudio VAR FINANCIALYEARNEXT = SELECTEDVALUE ( 'x Reference Dates'[FINANCIALYEARNEXT] ) VAR MBM_Id = "148" -- testing --VAR MBM_Id = 'Measure Benefit Master'[Id] -- uncomment for pbi desktop VAR CHECKPOINTNEXT = SUMMARIZE ( FILTER ( VALUES ( 'Measure Benefit Progress List' ), VALUE ( 'Measure Benefit Progress List'[Financial Year Search] ) = VALUE ( FINANCIALYEARNEXT ) && 'Measure Benefit Progress List'[Main ID LkUpId] = MBM_Id ), [CheckPoint] ) ) RETURN { CHECKPOINTNEXT }Solved809Views0likes2CommentsModa (medida de tendência central, valor que mais se repete) de uma coluna virtual.
Olá, Preciso calcular a moda (medida de tendência central da estatística, valor que mais se repete) de uma coluna virtual de quantidade de clinetes por semana. Minha coluna é virtual, e para calcular qual é o valor que mais se repete dessa coluna preciso fazer uma outra tabela virtual para contar quantas vezes cada valor se repete. mostrar o maior valor. Fiz, porém deu erro. Segue o print. Alguém consegue me ajudar com essa medida?6.9KViews0likes1CommentAdd extension column with If Statement
Good day experts I am trying to add a column to an existing table in the data view using a DAX query. The requirement is to determine the second half of the fiscal year using today's date. If the date falls in this 2nd half of the year, the term "HTD2 (Oct - Mar) " must be added in the Type column, and the value 3 in the Order column. As the fiscal year stretches from April to March, the second half falls over the change from one calendar year to the next. With the currently used calculation, if the current month is Oct, Nov or Dec, the calculation is incorrect. The current calculation is as follows: ADDCOLUMNS( CALENDAR( (DATE(YEAR(TODAY())-1,10,1 )), (DATE(YEAR(TODAY()),3,30 ))) , "Type", "HTD2 (Oct - Mar) ", "Order", 3) I am trying to create something like below, but my DAX knowledge is limited and I can't get it to work: IF(MONTH(TODAY())<10, ADDCOLUMNS( CALENDAR( (DATE(YEAR(TODAY())-1,10,1 )), (DATE(YEAR(TODAY()),3,30 ))) , "Type", "HTD2 (Oct - Mar) ", "Order", 3), ADDCOLUMNS( CALENDAR( (DATE(YEAR(TODAY()),10,1 )), (DATE(YEAR(TODAY()+1),3,30 ))) , "Type", "HTD2 (Oct - Mar) ", "Order", 3)) Could you please assist?Solved847Views0likes3CommentsUnable to use AddColumns Summarize with Calculated Dimension
I am working with both forecasts and actuals, and I would like to create a version which is called "Forecast + Actuals" which is a combination of actuals and the forecast values which is after the last date of actuals. I know you can do this via a measure like if selected value = "Forecast + Actuals" then return calculate measure, but I would prefer to do it in one measure to reduce the complexity of my measure tree. Here is an example data set. Date Version Value 31-Oct Forecast 100 30-Sep Forecast 150 30-Sep Actual 120 31-Aug Actual 100 Here is the Version Dimension table. "Forecast + Actuals" doesn't exist in my fact table, but can be derived from the fact table through a combination of Forecast and Actuals. Version Dimension Table Forecast Actuals Forecast + Actuals I would like a measure which would populate the following: Version 8/31 9/30 10/31 Forecast 150 100 Actuals 100 120 Forecast + Actuals 100 120 100 I was trying to accomplish it like this via this measure: DataSum = VAR MaxActualsDate = CALCULATE ( MAX ( FactTable[Date], Version = "Actuals" ) ) VAR SummaryData = ADDCOLUMNS ( SUMMARIZE ( 'FactTable', 'Date'[Date], Versions[Version] ), // this is the core table "@SourceValue", CALCULATE ( SUM ( FactTable[Value] ) ) ) RETURN IF ( SELECTEDVALUE ( Versions[Version] ) = "Current Forecast + Actuals", CALCULATE ( SUMX ( SummaryData, [@SourceValue] ), [Version] = "Actuals" ) + CALCULATE ( SUMX ( SummaryData, [@SourceValue] ), [Version] = "Forecast", Date[Date] > MaxActualsDate ), SUMX ( SummaryData, [@SourceValue] ) ) I didn't find any success here - so then I decided to modify the variable table by unioning the "Forecast + Actuals" into the SummaryData variable table. When i look at this in DAX studio, the table does have "Forecast + Actuals" with values, however, I am unable to bring this into a visual. DataSum = var MaxActualsDate = calculate( max(FactTable[Date],Version="Actuals") Var SummaryData = ADDCOLUMNS ( TREATAS ( UNION ( SUMMARIZE ( 'FactTable', 'Date'[Date], Versions[Version] ), // this is the core table ADDCOLUMNS ( SUMMARIZE ( FactTable', 'Date'[Date], Versions[Version] ), "Version", "Current Forecast + Actuals" // this is where i'm trying to add the "fake data series" ) ), 'Date'[Date], Versions[Version] ), "@SourceValue", IF ( [Version] = "Current Forecast + Actuals", CALCULATE ( SUM ( FactTable[Value] ), ALL ( Versions ), Versions[Version] = "Actuals" ), CALCULATE ( SUM (FactTable[Value]) ) ) Return Sumx ( SummaryData, [@SourceValue])Solved504Views0likes1CommentADDCOLUMNS and SUMMARIZE - incorrect Total (Live Connection)
Please see below issue: As you can see, for the No of Sessions, the total should be 9, but i'm getting a total of 32 insead which is super weird. Since we're using a Live Connection, I don't have access to calculated columns. See below DAX I used: No of Sessions = VAR SessionsTable = ADDCOLUMNS ( SUMMARIZE ( 'Location-Practice-Rendering', 'Location-Practice-Rendering'[LeafName] ), "Total Encounters", [Encounters], "No of Days Total", [No of Days], "No of Sessions Per Day", IF ( [Encounters] <= 2, 0, IF ( [Encounters] > 10, 2, 1 ) ) ) RETURN SUMX( SessionsTable, [No of Days Total] * [No of Sessions Per Day]) Where [Encounters] and [No of Days] are measures: Encounters = CALCULATE ( [Amount], FILTER ( ALL ( 'Profitability Account' ), 'Profitability Account'[Description] = "Encounters" )) No of Days = CALCULATE ( DISTINCTCOUNT ( 'Time'[CalendarDate]), FILTER ( 'Time', 'Time'[DayOfWeekdayDescription] <> "Sunday" && 'Time'[DayOfWeekdayDescription] <> "Saturday" ) ) We created the following DAX measure which gives us the correct results, BUT it takes hours to load, where as my DAX above takes seconds. The following DAX gives us correct results: No Of Sessions Day = VAR _encounters = CALCULATE ( DISTINCTCOUNT ( 'Transaction Attributes'[Encounter Number__EBM__Encounter Number] ), FILTER ( 'Transaction Attributes', 'Base Measures'[Encounters] > 0 ) ) RETURN SWITCH ( TRUE (), _encounters <= 2, 0, _encounters >= 2 && _encounters <= 10, 1, _encounters > 10, 2 ) Total No of Sessions = VAR SessionsTable = SUMMARIZE ( 'Fact', 'Fact'[CustomerID], 'Fact'[CalendarDate], "No of Days Total", CALCULATE ( DISTINCTCOUNT ( 'Fact'[CalendarDate] ) ), "No of Sessions Per Day", [No Of Sessions Day] ) RETURN SUMX ( SessionsTable, [No of Days Total] * [No of Sessions Per Day] ) Here are the results from the above DAX: Can you please help me amened my original DAX so I can get the correct results? The ADDCOLUMNS SUMMARIZE works a lot faster. Unless we can fix the second DAX to make it faster? amitchandak - you have any thoughts on this issue? Any help would be much appreciated 🙂907Views0likes3CommentsSum for last days of month per each category - how to simplify
Hello, I have a quite peculiar problem. I have a column with values that represents the state of Inventory for each Site (category). Which means that the most recent one value for each month is always last day per each site per month. Example for site 667 for november its going to be value 5 252 235.74 (31/12/2021) but for site 200 its going to be 79 967 894.18 (30/12/2021) The sum of those values should be 85 220 129.92 which is state of inventory for those two sites per december. I was able to calculate this with this measure: Inventory Cost = VAR _pretable = ADDCOLUMNS ( SUMMARIZE ( v_factinventorytransactions, v_dimdate[DateId], v_factinventorytransactions[SiteId] ), "InventoryCost", CALCULATE ( AVERAGE ( v_factinventorytransactions[RunningCost] ) ) ) VAR _table = FILTER ( _pretable, VAR _MaxDate = CALCULATE ( MAX ( v_factinventorytransactions[InventoryTransactionDateId] ), ALLSELECTED ( v_dimdate[DateId] ) ) RETURN v_dimdate[DateId] = _MaxDate ) RETURN SUMX ( _table, [InventoryCost] ) Which works perfectly but I'm wondering if it can be simplyfied. I want it to simplify, because when I want to use this measure inside another one that sums those Inventory Cost values per month for last 3 months and I have wrong answers. Which means that this Inventory Cost measure works but if I call out this measure in the one below it shows wrong numbers (but other measures, more simply ones work). Rolling3Months = VAR _EndDate = MAX(v_dimdate[Date]) VAR _Dates = DATESINPERIOD(v_dimdate[Date], _EndDate, -3, MONTH) VAR _Cost = [Inventory Cost] VAR _Inventory = SUMX(_Dates, CALCULATE(_Cost, ALL(v_dimdate[YearMonth]))) RETURN _Inventory I'm a little bit stuck and would be super appreciated when someone would pointed out my mistakes/errors here. I'm also providing sample power BI file with those. https://we.tl/t-eQSOYHm1ft Thank youSolved486Views0likes1CommentSUMMARIZECOLUMNS Alternative
Hello all, In my data model, besides the fact table, there is a target table, which contains one target value per date and dimension. Facts: Targets: The target value should be weighted at denominators of the fact table. I have tried different approaches to realize this. The only one that works so far is to add calculated columns in the fact table, which can then be divided in the measure. For each day and dimension, I calculate the associated target value, which I multiply by the denominators: Target Average = var relevantRows = FILTER( Targets, Targets[Date] = 'Facts'[Date] && Targets[Dimension] = 'Facts'[Dimension] ) var foo = SELECTCOLUMNS(relevantRows, "Target", [Target]) return foo Target Absolut = Facts[Denominator] * Facts[Target Average] Weight = IF(NOT(ISBLANK(Facts[Target Average])), Facts[Denominator]) The result is as expected and correct regardless of the choice of dimension: I am very interested in a Measure-based solution. With SUMMARIZECOLUMNS I could display the correct value. However, this function has some limitations so it stops working as soon as the dimension or date is brought into the context/visual. (the second image shows what happens when I activate the SUMMARIZECOLUMNS measure in the first visual. The error message appears that SUMMARIZECOLUMNS cannot be used in this context). Target via Measure SUMMARIZECOLUMNS = VAR _table = ADDCOLUMNS ( SUMMARIZECOLUMNS ( 'Date'[Date], 'Dimension'[Dimension], "_weight", SUM ( 'Facts'[Denominator] ), "_target", MAX ( 'Targets'[Target] ) ), "_target absolut", [_weight] * [_target] ) VAR _tableFiltered = FILTER ( _table, NOT ( ISBLANK ( [_target absolut] ) ) ) RETURN DIVIDE ( SUMX ( _tableFiltered, [_target absolut] ), SUMX ( _tableFiltered, [_weight] ), BLANK () ) As an alternative for this I have worked with SUMMARZIZE and ADDCOLUMNS, but fail to get the dimension and date into a virtual table. This results in an incorrect value as long as the dimension is not selected: Target via Measure SUMMARIZE = var _table1 = SUMMARIZE( 'Date', 'Date'[Date], "_weight", SUMX(RELATEDTABLE('Facts'), 'Facts'[Denominator]), "_target", MAXX(RELATEDTABLE('Targets'), 'Targets'[Target]) ) var _table2 = ADDCOLUMNS(_table1, "_targetAbsolut", [_weight] * [_target] ) RETURN DIVIDE(SUMX(_table2, [_targetAbsolut]), SUMX(_table2, [_weight]), BLANK()) I know that in the virtually created table, the dimension information is missing. But I have no idea how to implement this. The requirement is to get the result from [Target via Columns] or [Target via Measure SUMMARIZECOLUMNS] without any additional calculated columns and not make any change in the relationships. Does anyone have any idea about this? Thanks in advance and kind regards ChrisSolved3.8KViews0likes3Comments