My calculated member is not working - visual-studio-2010
I tried to create a calculated member for displaying profit for each product, but I got an error on the "select". Can anyone help me out with this since I am newbie in this?
CALCULATE;
CREATE MEMBER CURRENTCUBE.[Measures].Profit_Per_Produkt
AS Select [Measures].[Vinst] on columns,
[Dim Produkt].[Artikelnr].[Artikelnr] on rows
from [Elektronikkedja],
FORMAT_STRING = "Percent",
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Fact Köp' ;
A calculated member you should contains a calculate expression as:
([Measures].[Internet Sales-Sales Amount] -
[Measures].[Internet Sales-Total Product Cost]) /
[Measures].[Internet Sales-Sales Amount]
See on technet Defining Calculated docs a some samples.
Related
DAX formula to get total number of sales in a Calculated Column at a lookup table
I have received answers to my last question. Thanks to all. Now I have another query. I have a lookup table, called Products and a transaction table, called Sales. The relationship between them is one to many. I want to make a Calculated Column at Product to get the total number of sales for each product. I tried to apply Calculate function as solution. Product [total number of sales] = Countrows ( Filter (Product, Calculate (Sum( Sales [SalesAmount])))). I expected products in each row in Product table shall filter the sum of sales amount and generate a virtual table with all the entries related to a particular product. And finally, Countrows shall count the number of entries. But on the contrary, it resulted with same number in each row. I am just a beginner in DAX. I tried to solve it depending on context transition concept. But my guess was wrong. Please help me out. Thank you in advance.
Use RELATEDTABLE: If you just want the number of entries in the Sales table per product: = COUNTROWS( RELATEDTABLE( Sales ) ) If you want the total sales per product: = SUMX( RELATEDTABLE( Sales ), Sales[SalesAmount] )
Calculated Column in DAX (Power BI): Fill down formula to add missing information
Looking for a calculated column to complement missing information in my table. My data looks like this: Each article is listed online/offline for a couple of days. I want to extend the online/offline status of each article until the first day it officially changes its status again. Please note that some articles report sales information before they are officially listed online/offline. These blank status fields should be filled out accordlingly as well (see below). Thanks in advance - David
Create a calculated column that either uses status, if there is one, or uses Sales Date to work out the previous status value Complete Status = VAR PreviousRow = TOPN ( 1, FILTER ( Online, Online[Sales Date] < EARLIER ( Online[Sales Date] ) ), [Sales Date], DESC ) VAR PreviousValue = MINX ( PreviousRow, [Status] ) VAR StatusOrPreviousValue = IF (OR(ISBLANK(Online[Status]), Online[Status]=""),PreviousValue, Online[Status]) RETURN StatusOrPreviousValue
TOPN DAX function not working. The formula is returning all the rows and not TOP 3
My goal is to create measure to get top 3 customer Names and there respective sales. I am using the below measure to bring top 3 names along with there sales. The below measure is returning all the rows. I fail to understand why this is happening and why filtering is not happening for top 3 customers topN = calculate(sum(Sale[Total Excluding Tax]), TOPN(3, values(Sale[Employee Name]), calculate(sum(Sale[Total Excluding Tax])) ) ) Sale[Employee Name] is calculated column and is coming from another table Employee by using Employee Name = RELATED(Employee[Employee])
The DAX is working properly and grabbing top 3 records. Order/sorting is important. You need to order your results. Create a calculate column [Total Excluding Tax] to sum up the Total excluding tax. Then use that column in a measure; try something like: Top Sales = TOPN ( 3, ALLSELECTED( 'Sale' ), [Total Excluding Tax]), desc)
Dax - Filter by value then count occurence in table
I am working with an employee table and was wondering if I could get some help. My data table has rows with start and end date values. I filter these rows down using Filter(data table, [start date]<=[Measure.MaxMonth]&&[end date]>=[Measure.MaxMonth]. [Measure.MaxMonth] is a measure that sits on a disconnected date table and functions like a parameter. Here is a formula that I have been testing but have not been getting the desired results: Measure.DirectReports = CALCULATE(COUNTROWS(Data Table),filter(Data Table,Data Table[Mgr ID]=Data Table[Emp ID]&&Data Table[Start Date]<=[Meas.LastMonth]&&Data Table[End Date]>=[Meas.LastMonth])) Measure.LastMonth = max(EOM[End of Month]) ->this value can equal any month end between July 2005 and July 2017. EOM is a date table with a row for each month end - 7/31/2005, 8/31/2005,....7/31/2017 This gives me a table structured liked this: Emp ID,Emp Attr,Mgr ID,Start Date,End Date 1,B,4,10/1/2013,10/6/2013 1,B,4,10/7/2013,12/29/2013 1,B,4,12/30/2013,12/28/2014 1,B,8,12/29/2014,10/4/2015 1,B,8,10/5/2015,12/27/2015 1,B,12,12/28/2015,5/15/2016 1,B,12,5/16/2016,10/2/2016 1,B,12,10/3/2016,12/25/2016 2,B,4,12/1/2014,12/28/2014 2,B,4,12/29/2014,12/27/2015 2,B,4,12/28/2015,2/7/2016 2,B,4,2/8/2016,3/6/2016 2,B,8,3/7/2016,6/1/2016 3,B,6,7/1/2015,12/27/2015 3,B,8,12/28/2015,6/30/2016 3,B,6,7/1/2016,9/4/2016 3,B,6,9/5/2016,12/25/2016 3,B,6,12/26/2016,5/7/2017 3,B,4,5/8/2017,6/11/2017 3,B,4,6/12/2017,6/25/2017 3,B,4,6/26/2017,7/9/2017 3,B,19,7/10/2017,12/31/9999 4,A,,7/1/1996,4/2/2006 4,A,,4/3/2006,12/31/2007 4,A,,1/1/2008,5/22/2011 4,A,,5/23/2011,11/16/2014 4,A,,11/17/2014,6/11/2017 4,A,,6/12/2017,6/25/2017 4,A,,6/26/2017,12/31/9999 5,B,4,11/8/2010,1/2/2011 5,B,4,1/3/2011,5/22/2011 5,B,4,5/23/2011,1/1/2012 5,B,4,1/2/2012,5/31/2012 5,B,4,6/1/2012,7/1/2012 5,B,4,7/2/2012,9/7/2012 6,B,4,1/3/2011,5/22/2011 6,B,4,5/23/2011,9/5/2011 6,B,4,9/6/2011,1/1/2012 6,B,4,1/2/2012,12/30/2012 6,B,4,12/31/2012,12/29/2013 6,B,4,12/30/2013,5/18/2014 6,B,4,5/19/2014,11/16/2014 6,B,4,11/17/2014,12/28/2014 6,B,4,12/29/2014,3/22/2015 6,B,4,3/23/2015,12/27/2015 6,B,4,12/28/2015,3/6/2016 6,B,4,3/7/2016,8/21/2016 6,B,4,8/22/2016,10/30/2016 6,B,4,10/31/2016,12/25/2016 6,B,4,12/26/2016,1/8/2017 6,B,4,1/9/2017,5/7/2017 6,B,4,5/8/2017,6/11/2017 6,B,4,6/12/2017,6/25/2017 6,B,4,6/26/2017,12/31/9999 7,B,4,1/2/2012,12/30/2012 7,B,4,12/31/2012,12/29/2013 7,B,4,12/30/2013,5/18/2014 7,B,4,5/19/2014,11/16/2014 7,B,4,11/17/2014,12/28/2014 7,B,4,12/29/2014,3/8/2015 7,B,4,3/9/2015,1/18/2016 7,B,4,1/19/2016,2/19/2016 8,B,6,12/31/2012,11/3/2013 8,B,4,11/4/2013,12/29/2013 8,B,4,12/30/2013,1/26/2014 8,B,4,1/27/2014,5/18/2014 8,B,4,5/19/2014,11/16/2014 8,B,4,11/17/2014,12/28/2014 8,B,4,12/29/2014,3/22/2015 8,B,4,3/23/2015,12/27/2015 8,B,4,12/28/2015,7/1/2016 10,B,4,10/3/2011,12/18/2011 10,B,4,12/19/2011,12/30/2012 10,B,4,12/31/2012,2/23/2013 10,B,4,2/24/2013,11/20/2014 11,B,4,2/1/2011,2/27/2011 11,B,4,2/28/2011,5/1/2011 12,B,4,9/15/2012,12/31/2012 12,B,4,9/15/2012,12/31/2012 12,B,4,1/1/2013,12/31/2013 12,B,4,1/1/2013,4/30/2014 12,B,4,1/1/2014,4/30/2014 12,B,4,5/1/2014,11/16/2014 12,B,4,5/1/2014,12/28/2014 12,B,4,11/17/2014,11/30/2014 12,B,4,12/1/2014,12/28/2014 12,B,4,12/29/2014,12/27/2015 12,B,4,12/29/2014,12/30/2016 12,B,4,12/28/2015,12/30/2016 12,B,4,12/31/2016,12/31/2016 12,B,4,1/1/2017,6/11/2017 12,B,4,6/12/2017,6/25/2017 12,B,4,6/26/2017,7/9/2017 12,B,19,7/10/2017,12/31/9999 13,B,4,12/28/2015,9/4/2016 13,B,4,9/5/2016,12/25/2016 13,B,4,12/26/2016,6/11/2017 13,B,4,6/12/2017,6/25/2017 13,B,4,6/26/2017,12/31/9999 14,B,4,1/12/2015,12/27/2015 14,B,4,12/28/2015,12/25/2016 14,B,4,12/26/2016,6/11/2017 14,B,4,6/12/2017,6/25/2017 14,B,4,6/26/2017,12/31/9999 16,B,4,9/14/2015,10/19/2015 17,B,6,8/22/2016,12/25/2016 17,B,6,12/26/2016,5/7/2017 17,B,4,5/8/2017,6/11/2017 17,B,4,6/12/2017,6/25/2017 17,B,4,6/26/2017,7/9/2017 17,B,19,7/10/2017,12/31/9999 18,B,6,9/12/2016,12/25/2016 18,B,6,12/26/2016,5/7/2017 18,B,13,5/8/2017,6/11/2017 18,B,13,6/12/2017,6/25/2017 18,B,13,6/26/2017,7/9/2017 18,B,19,7/10/2017,12/31/9999 19,B,4,7/10/2017,12/31/9999 Empl ID is a unique employee number. Mgr ID references the Empl ID of the employee's manager at the desired point in time (Measure.LastMonth). Emp Attr is an attribute of the employee, such as level. Does anyone have any ideas on how to create a measure that will count the occurrences of Empl ID in Mgr ID? Ideally, if I am creating a visual in Power BI and I filter based on Empl Attr ="A", can the resulting measure value give me the result = 3 -> the empl id "1" occurs 3 times in the mgr id column. I need this to be a measure and not a calculated column so that I can trend the results over time (end of month on X axis in trend visual). Thanks for the help and let me know if you have any questions!
Edit - Updating basically the entire answer due to new information about the problem. I feel that your core problem is trying to create a relationship between two tables based on the evaluation of an expression (End of Month between Start Date and End Date). From my experience, the easiest way to workaround this is to CROSSJOIN the two tables and then filter it down based on whatever expression you would like. For this, I created a new table with this formula. Results = DISTINCT( SELECTCOLUMNS( FILTER( CROSSJOIN('Data Table', EOM), 'Data Table'[Start Date] <= EOM[End of Month] && 'Data Table'[End Date] >= EOM[End of Month] ), "Emp ID", [Emp ID], "End of Month", [End of Month] ) ) One more piece before finally making the relationships, we need a list of unique employee IDs. That can easily be obtained by creating a new table with this formula. Employees = DISTINCT( SELECTCOLUMNS('Data Table', "Emp ID", 'Data Table'[Emp ID] ) ) From here, create relationships between all of the tables as shown in the image below. I know you asked for a measure, but bear with me as I feel confident that this will get you what you want. Add a new column to the Results table with this formula. DirectReports = CALCULATE( COUNTROWS('Data Table'), FILTER(ALL('Data Table'), 'Data Table'[Mgr ID] = EARLIER(Results[Emp ID]) && 'Data Table'[Start Date] <= EARLIER(Results[End of Month]) && 'Data Table'[End Date] >= EARLIER(Results[End of Month]) ) ) At this point, I would hide the Emp ID and End of Month from the results table and any other field(s) you desire. From there, make your visuals. For example, you said you wanted to show direct report count over time, so I made this simple line chart and card.
How to sort specific Hierarchy Level in OLAP (SSAS) via MDX
I'm using SSAS OLAP and I want to apply sorting of the levels of a hierarchy. I know that I can sort the whole hierarchy via ORDER function (I have some issues when I'm trying to apply DESC sorting on the whole hierarchy), but what I really want to achieve is sorting of a specific level. For example in the [Date].[Calendar] hierarchy (Adventure Works Cube), I want to have ASC sorting of years, DESC sorting of Quarter, ASC sorting of Months, etc. I do not want to break the hierarchy (using BASC or BDESC), I just need them sorted on the same level. Do you have an idea if this is possible at all, as I was unable to find anything simillar?
What you can do is crossjoining the ordered correspoding attribute hierarchies. Could you verify the results of the following: select [Measures].[Internet Sales Amount] on 0, Order( [Date].[Calendar Year].[Calendar Year].MEMBERS, [Measures].[Internet Sales Amount] ,ASC) * Order( [Date].[Calendar Quarter of Year].[Calendar Quarter of Year].MEMBERS, [Measures].[Internet Sales Amount] ,DESC) * Order( [Date].[Calendar].[Month].MEMBERS, [Measures].[Internet Sales Amount] ,ASC) ON 1 from [Adventure Works] Including the all members could help ([Date].[Calendar Year] instead of [Date].[Calendar Year] in case of the first crossjoin set) Philip,
The following is a working solution, if not a really nice one: WITH MEMBER Measures.[year] as [Date].[Calendar].CurrentMember.Properties('Key0', typed) MEMBER Measures.[qtr or mth] as [Date].[Calendar].CurrentMember.Properties('Key1', typed) MEMBER Measures.[sortKey] as CASE WHEN [Date].[Calendar].CurrentMember.Level IS [Date].[Calendar].[Calendar Year] THEN Measures.[year] * 1000 WHEN [Date].[Calendar].CurrentMember.Level IS [Date].[Calendar].[Calendar Quarter] THEN Measures.[year] * 1000 + (5 - Measures.[qtr or mth]) * 100 ELSE // month Measures.[year] * 1000 + (4 - Int((Measures.[qtr or mth] - 1) / 3)) * 100 + Measures.[qtr or mth] END SELECT {Measures.[year], Measures.[qtr or mth], Measures.[sortKey]} ON COLUMNS, Order( [Date].[Calendar].[Calendar Year] + [Date].[Calendar].[Calendar Quarter] + [Date].[Calendar].[Month] , Measures.[sortKey] ,BASC ) ON ROWS FROM [Adventure Works] The measures on the columns are just for clarification how it works. And the main logic is in the generation of the sortKey measure which generates an integer key as follows: four digits for the year, one digit for the backwards quarter (Q4 -> 1, ... Q1 -> 4), two digits for the month. Then, using that, it is straightforward to call Order to return the sorted set.
It turned out that it is impossible to achieve the desired effect - there's no such MDX query that can sort different levels with different sorting type. More information is available in this thread.