Using PowerBI linked to two separate Access Databases.
I have two datasets containing cost estimates. The cost estimates in Dataset 1 run through 2054; the cost estimates in Dataset 2 run through 2074. I used the Append function to join the two tables together and used the Quick Measure for Running Total to create values for cumulative cost by year. I charted this measure and noticed a significant decrease between 2054 and 2055 and was able to determine that the decrease is the cumulative value for Dataset 1. Does anybody know any ways to fix this?
Roughly explained:
Dataset 1 through 2054 totals to 4.5M.
Dataset 2 through 2054 totals to 3M
Dataset 2 through 2055 totals to 3.25M
Appended Dataset through 2054 totals to 7.5M
Appended Dataset through 2055 totals 3.25M instead of the expected 7.75M
I think the issue might be caused by Dataset 1 not having a value for 2055 or after, but I'm not sure how to resolve this issue.
The measure I'm using is:
Cumulative Cost =
CALCULATE(
SUM('AppendedQuery'[Value]),
FILTER(
ALLSELECTED('AppendedQuery'[Year]),
ISONORAFTER('AppendedQuery'[Year], MAX('AppendedQuery'[Year]), DESC)
)
)
ETA: Picture to explain
Here is your Dataset 1-
Here is your Dataset 2-
Here is your final Dataset after appending Dataset 1 & 2
And finally, here is the output when you are adding column Year and Cumulative Cost to a table visual. As standard PBI behavior, this is just grouping data using column Year and and applying SUM to the column Cumulative Cost.
The calculations are simple-
2051 > 1 + 1 = 2
2052 > 2 + 2 = 4
2053 > 3 + 3 = 6
2054 > 4 + 4 = 8
2055 > 5 = 5
2056 > 6 = 6
=========================
Solution for your case:
I already said in the comments that the solution current data will be not a standard one and will consider fixed $1 per year per department. But if you are happy with this static consideration, you can apply these following steps to achieve your required output-
Step-1 Create a Custom Column as below (Adjust the table name as per yours)-
this_year_spent = IF('Dataset 3'[Cumulative Cost] = BLANK(),0,1)
Step-2 Create the following Measure-
cumulative =
VAR current_year = MIN('Dataset 3'[Year])
RETURN
CALCULATE(
SUM('Dataset 3'[this_year_spent]),
FILTER(
ALL('Dataset 3'),
'Dataset 3'[Year] <= current_year
)
)
Here is the final output-
Related
I am having an issue using the Distinctcount function in DAX. I have a table with a total of 1,154,493 rows. I have a measure created to count the number of distinct values in column 1. I have another measure created to count the number of distinct values in column 1 with filters. I have a 3rd and final measure created to count the number of distinct values of column 1 with different filters. The issue I am running into is the count of measure 2 + measure 3 should equal measure 1 however added together they are GREATER than the value of measure 1 which is just a grand total. How is this possible? Unfortunately I can't share the table but below is the code I am using for the two measures:
Measure1=distinctcount('Table1'[Column1])
Measure2=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 1,'Table1'[CTest2] = "07")
Measure3=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 2,'Table1'[CTest2] = "07")
I am at a loss. Thank you in advance!!
For troubleshooting you should identify values of Column1 with Measure2 and Measure3 > 0, those are being added twice.
I have a problem with calculating measure that sums values for 3 previous periods.
Below I attach sample fact table and dict table to show problem I am facing.
date
customer
segment
value
01.01.2021
1
A
10
02.01.2021
1
A
10
03.01.2021
1
A
10
04.01.2021
1
A
10
01.01.2021
2
B
20
02.01.2021
2
B
30
03.01.2021
2
B
40
dict table:
segment
segment_desc
A
Name of A
B
Name of B
Approach I have taken:
last 3 value =
VAR DATES = DATESINPERIOD(facts[date],LASTDATE(facts[date]), -3,MONTH)
RETURN CALCULATE([sum value], DATES)
It produces correct results as long as there is at least one record for April.
When I use filter on segment_desc = 'B'
It produces result as I attached - so we see result in April equals 20, which is obviously not what I wanted. I would expect it to be 50.
Answer to the main question:
time intelligence functions like DATESINPERIOD require a proper calendar table, because they expect continuous dates, without gaps.
Answer to the follow-up question "why the measure shows value for January?"
It's a bit tricky. First, notice that LASTDATE in this filter context returns blank:
So, your DAX measure then becomes this:
last 3 value =
VAR DATES = DATESINPERIOD(facts[date], BLANK(), -3,MONTH)
RETURN CALCULATE([sum value], DATES)
Blank - 3 month does not make sense, so the way DAX resolves this: it replaces BLANK with the first (min) date in the table. In this case, it's 1/1/2021. Then it goes back 3 months from that date. As a result, the final measure is:
last 3 value =
CALCULATE([sum value], {2020-11-01, 2020-12-01, 2021-01-01 })
Since you have no data prior to 2021-01-01, the final result shows only January values.
I am trying to create a measure that calculates (a/qty)*100 for each month,
where qty commes from Delivery table (generated with an R script)
month qty
<date> <dbl>
1 2019-02-01 1
2 2019-03-01 162
3 2019-04-01 2142
4 2019-05-01 719
And a comes from a table TABLE_A that has been created within Power BI that looks like this :
Client Date a
x 2019-03-07 3
x 2019-04-14 7
y 2019-03-12 2
So far, I managed to calculate that value overall with the following measure formula :
MEASURE = CALCULATE( (Sum(TABLE_A[a])/sum(Delivery[qty]))*100)
The issue I have is that I would need this measure monthly (i.e. join the tables on month) without explicitly defining a link between the tables in the PowerBI model.
For each row in TABLE_A you need to look up the corresponding qty in Delivery, so try something along these lines:
MEASURE =
DIVIDE(
SUM( TABLE_A[a] ),
SUMX(
TABLE_A,
LOOKUPVALUE(
Delivery[qty],
Delivery[month], EOMONTH( TABLE_A[Date], -1 ) + 1
)
)
) * 100
The formula EOMONTH( TABLE_A[Date], -1 ) returns the end of the previous month relative to that date and adding 1 day to that to get the start of the current month for that date.
I have a table with three columns - list_id, id, daily_return. id is basically a number sequence increment, reset for every list_id.
Example:
list_id id daily_return
1 1 0.2
1 2 0.18
1 3 0.35
2 1 0.15
2 2 0.18
2 3 0.23
I need to create a calculated measure on the chart I am creating such that it creates a running total of daily_return for the same list_id, ordered by the id column.
I am creating a measure in the chart, since I want the rows to be filtered by the user and the calculation itself will be more complex.
How do I get the current list_id and id, so I may use it in my formula?
This is what I have so far. I tried using EARLIER/EARLIEST without success.
cumulative_return = CALCULATE(SUM('CMC Daily Return'[daily_return]), 'CMC Daily Return'[list_id]=EARLIER([list_id]), 'CMC Daily Return'[id]<=EARLIER([id]))
I came up with the following formula that works, but if there is a better one, then I am all ears.
cumulative_return = CALCULATE(SUM('CMC Daily Return'[daily_return]), FILTER( ALLSELECTED('CMC Daily Return'), 'CMC Daily Return'[list_id] = max('CMC Daily Return'[list_id]) ), FILTER( ALLSELECTED('CMC Daily Return'), 'CMC Daily Return'[id] <= max('CMC Daily Return'[id]) ) )
I am looking for unit counts when the equipment is not in the date range (start and end dates).
How do I make a measure "AvailUnitCount" to give me unit counts by category in the timeline dimension (say November 11, 2018)?
I think it can be achieved via a measure in Power Pivot and date table, but I am just quite new to DAX and time dimension concept overall.
My measure reads:
AvailUnitCount := CALCULATE( DISTINCTCOUNT( EquipUsage[EquipmentNo] ) )
How do I incorporate time dimension into the measure above, so I can report on available equipment for a specific date by moving a timeline in Excel?
Please see the data set and the desired outcome below. I immensely appreciate your advice on this.
Table 1: EquipUsage
EquipNo CategoryNo UsageStartDate UsageEndDate
----------------------------------------------------
10005164 A020004004 5-Nov-18 5-Dec-18
10005167 A020004004 24-Oct-18 10-Nov-18
10005176 A020004005 9-Oct-18 5-Dec-18
10015982 A020004006 18-Feb-18 5-Sep-18
10019170 A020004006 16-Aug-18 30-Mar-19
10019551 A020004006 2-May-17 10-Nov-18
10005178 A020004007 20-Sep-18 15-Jan-19
Table 2: EquipCategories (Example of Desired Outcome for November 11, 2018)
CategoryNo AllUnits AvailableUnits
--------------------------------------
A020004004 2 1
A020004005 1 0
A020004006 3 2
A020004007 1 0
The AllUnits measure is simple:
AllUnits = COUNTROWS(EquipUsage)
For availability, read in your desired date and sum up the rows where that date does not fall in the given date range:
AvailableUnits =
VAR CheckDate = SELECTEDVALUE(DateTable[Date])
RETURN SUMX(EquipUsage,
IF(
EquipUsage[UsageStartDate] <= CheckDate &&
EquipUsage[UsageEndDate] >= CheckDate,
0,
1
)
)