I am sure this is really easy to do but could some one tell me what I am doing wrong.
I have this table
When I add a new measure to do Target -Total Amount I get additional lines.
How do I remove these so it is aggregates?
reference for relationships
Salesperson is the same as Employee name
This is due to absence of some 'Sales person' in 'Sales Transaction'.[Saleseperons]
Change 'Sales Transaction'.[Saleseperons] to 'Sales person]'.Name in the matrix
Try to wrap your calculation in a CALCULATE().
Related
I have 2 tables.
I am joining both of them via a 1 to many relationship.
The KPI I want to use is in Table_1, but I'm grouping it based on a column in Table_2.
When I throw the measure onto PowerBI, it gives the same value for all rows.
I created the measure like this:
sales_in_cents := (sum(Table_1[Sales]) * 100)
When I group the data using a column from Table_2, it gives me the same value for each row in Table_2.
Why is this?
How do I fix it?
Edit #1
It's similar to this, but I do have a relationship.
Edit #2:
Table_1 has a 1 to many relationship with Table_2 and cross filter direction is set to single.
Edit #3:
I think I need to use some sort of combination of the LookUpValue and/or RelatedValue Function.
Table_1 has a 1 to many relationship with Table_2 and cross filter direction is set to single.
That means that Table_1 can filter Table_2, but not the other way round. This is why you get repeated values when using a column from Table_2 and a measure based on the Table_1, the filter context doesn't propagate
How to solve it
Measure with TREATAS:
https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/
Calculated column in Table_2 that would use RELATED (as each row in Table_2 has a single, related row in Table_1, for referencing the many side you need to use RELATEDTABLE)
changing the relationship to bidirectional - it can create ambiguity, so I don't recommend it
This model seems a bit peculiar, is it something like a Table_1 is monthly budgets, while Table_2 is daily sales? In general star schema is recommended in the tabular models, it makes life much easier if you can use that schema
I currently have a raw data table called Score Table which has three columns: (1) an entity ID, (2) a score, and (3) a date.
I also have a Measure for a single dynamic date (I can't use date slicers for this for reasons that I won't bore you with).
My goal is to have a measure tell me what the last score is before the date indicated by the Measure.
I for some reason am unable to pull this off in DAX. Whenever I try to use Calculate( functions in DAX, I end up only pulling the final date in the 'Score Table' [Date] column (not before the Measure date and not different by ID.
Any help on this would be greatly appreciated.
I still miss some information to give you a specific answer, but something like this should work.
PreviousScore =
CALCULATE(
LASTNONBLANK('Table'[Score])
,FILTER(
ALL('Calendar')
,'Calendar'[Date] < [YourDateMeasure]
)
)
Note that I'm assuming you have a Calendar table to manage the dates (you usually want one of those in your model)
I have data from multiple countries on a monthly basis. Since the updates are not regular, I want to set up filter to visuals, so they would show the last month for which I have data from all the countries. I have data from each country loaded into a separate dataset, which then are merged into one big. Is there an easy way to place such filter? I managed to use "LASTDATE" function in each of country sets to find which date is last, but if I try to filter with that measure, I simply get nothing in a result. Thanks!
Well, this feels a little clunky to me but I believe it will work for you. There are two steps. The first is to create a summary table that reads through your data and counts the number of distinct countries that you have in each month. This will be a new table in your model, so go into the modeling tab, click 'New Table' and add this DAX. Obviously, correct for your table and column names.
SUMMARIZED_ROWS = SUMMARIZE(
'Table1'
,Table1[Month]
,"CountOfCountries"
,DISTINCTCOUNT(Table1[Country])
)
Now add a measure to the table (or anywhere) like this:
MonthWithMostCountries = CALCULATE(
LASTNONBLANK(SUMMARIZED_ROWS[Month], 1 )
, FILTER(SUMMARIZED_ROWS, SUMMARIZED_ROWS[CountOfCountries] = MAX(SUMMARIZED_ROWS[CountOfCountries]) ) )
This is going to give you the month where you have the most distinct countries in your data. You'll want to look at it in a card or similarly isolated visual as it is a measure and can be affected by filter context.
So, on the left is my mock data - 3 countries, 3 months each with a 1 month stagger. On the right you see the result of the Summarize table. Then the measure showing the final result.
Hope it helps.
I want to create a simple percent change formula in power BI. Specifically, I want to evaluate month over month %change in cost. I know that percent change can be defined in different ways, so to be clear this is the formula that I am referring to:
%change = ([current value] - [previous value])/[previous value].
Here is an example in Excel of what I want to achieve:
I cannot find a way to target a specific row in a DAX formula. It seems that power BI only wants to include aggregate values such as sum, max, etc.
As a final note, I know that PowerBI includes a percent change "quick measure". However, the 'Base Value' always requires you to select aggregate measure instead of a single row value.
As Alexis mentioned, there is no concept of referring to a specific row in DAX. It can be a hard notion for people who are used to Excel, but if you want to take advantage of PowerBi, you will have to "unlearn" Excel way of thinking.
To accomplish your goal, you need to do some data modeling first. As a common practice, replace your "Date" column with a proper Calendar table:
Calendar table explained
As a result, you will have a data model in PowerBi that looks something like this:
Once you have such structure in place, DAX is simple:
Current Month Cost = SUM(Expenses[Cost])
Previous Month Cost = CALCULATE( [Current Month Cost], PREVIOUSMONTH(Calendar[Date]))
% Change = DIVIDE( [Current Month Cost] - [Previous Month Cost], [Previous Month Cost])
I used Earlier to get the previous date value for Open
Accum = var previousOpen=CALCULATE(MAX(EOG[Open]),FILTER(EOG,EOG[Date]<EARLIER('EOG'[Date],1))) return Divide(EOG[Open]-previousOpen,previousOpen)+1
I have a powerbi report which is running a dax formula to calculate a custom measure. In the picture below, the total at the bottom doesn't seem to add up to the individual rows. I've been trying my luck for some time and can't seem to figure out why this is.
The DAX formula used is as follows
SumRest<24hrs7Day = CALCULATE(
DISTINCTCOUNT(WorkTimeDirective[EmployeeKey]),
FILTER(
ADDCOLUMNS(
SUMMARIZE(WorkTimeDirective,Employee[EmployeeKey],'Date'[DateKey]),
"totRestHrs", CALCULATE(MAX(WorkTimeDirective[RestHours])
,DATESINPERIOD('Date'[DateKey], LASTDATE('Date'[DateKey]), -7, DAY))
),
[totRestHrs]<24
),
WorkTimeDirective[IsEmployeeAbove18]=1
)
Any idea why this is and what I am doing wrong.
For using SUMX the main step is listing the values which you are iterating over, which it typically a table or column. In this case it sounds like you would do a column.
For the example I just had it call the measure you already defined, since breaking DAX calculations into smaller pieces makes writing/testing complex formulas easier.
The idea being that it would iterate over the unique values which are in your TableName[Site Name], then run the [SumRest<24hrs7Day] under that context. I used TableName for the table due to not knowing the name for the table.
SUMX_Example = SUMX( VALUES( TableName[Site Name], [SumRest<24hrs7Day])