It is impossible to determine a unique value for the column PowerBi - powerbi-desktop

Good evening to all. I have a problem with powerbi that I can't solve:
I have the following data stored there (for simplicity, I have voluntarily reduced the size of the table):
https://files.fm/u/yx9y4mrun
id: the id of a person. Here we have three persons
Name: represents an activity performed by a person. Here we have only two activities: activity 1 and activity 2
Value: the value transmitted by the person.
Date: the date and time of transmission.
As you can see, a person can send several data in one day, at different dates and times. Now I want a table in powerbi that represents the data as follows
a column that represents the first date of data transmission by a person (I did this using a measure that I named "first" with the formula MIN(Donnee[Date]))
a column that represents the last date of data transmission by a person (I did it using a measure that I named "last" with the formula MAX(Donnee[Date]))
a column that displays for each patient the n-th day of transmission (roughly if it is day 1 or 2 or 3)
For the latter, I wanted to make a DATEDIFF(Donnee[Date]-Donnee[last], DAY) +1. But I have the following error:
It is impossible to determine a unique value for the "Date" column in the "Data" table. This can happen when a measurement formula refers to a column that contains many values, without specifying an aggregation such as min, max, count or sum to get a unique result.

Related

How to calculate average of parent category in excel?

I have data in below format. It shows starting and end time of an activity and calculates duration accordingly. The activity is performed through out the day at different times.
I have added a pivot. I want to find out the average duration in a workday or a holiday(Day category). When I am trying to apply average in the current pivot, it is dividing the total duration by the number of sessions in a day.For example in week 1, an activity was done on 4 work days and the total duration for the activity in workdays was 04.19, I want to divide this number by 4 and find out the average time spent on each day but the pivot divides it by 11 which is the total number of sessions in the four days.
Link for data
Steps:
Add a helper column to identify how many unique pairs of Dates/Day Categories there are:
=IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)
You can add extra products to this formula to force extra fields to be unique to be counted as well.
SRC:Simple Pivot Table to Count Unique Values
Add a Calculated Field in the PivotTable that is:
SUM(Duration)/SUM([Helper Column Name]) and include it in the 'Values' section of the PivotTable. Due to the new column being added, you might have to re-create the PivotTable.
This should produce the average in the manner that you want.

Spotfire: calculating difference between two rows in same column based on attributes in different columns

I am new to Spotfire and need help in getting the right expression for a calculated column.
My Data contains different subjects grouped in column ID. For every ID, Bodyweight was measured on different days. Days are given in column Day and stated as 1,2,3...
The last day is denoted by Last and Bodyweight measurements given in another column. Another column is present which is called Baseline. The Body weight measured is considered as baseline if the column contains a Y for that row.
I need to insert a calculated column, which will contain the difference between Body measurement measured on Day denoted Last and Body measurement marked by Y in column Baseline.
This should be done for every new ID. I am not able to figure this out. Could someone advise me on how to go about it?
Here is an example attached
So, the calculated column for Rita will give -4 (body weight at Last=56 and BodyWeight at baseline=56, so 52-56 =-4)
the sample data you provided is a little weird, particularly the [Day] column. if it's within your control, I suggest to use actual dates rather than a number/string here.
barring that, I was able to get your desired results, but it required two calculated columns: the first one will consolidate the [Day] and [Baseline] columns into a single column, and the second one contains your desired info.
column 1, which I called Day (int):
CASE
WHEN [Day]="Last" THEN 1000000
WHEN [Baseline]="Y" THEN -1000000
WHEN [Day]!="Last" THEN Integer([Day])
END
I picked a random high and low max to establish a chronological order. this will put 1000000 in place of "Last" (if you have any programs that are longer than one million days, you'll need to increase this number). the same for the [Baseline] column, but that value will be -1000000, which is presumably the lowest value you will ever see in this column. both of these are assumptions and may not work for your implementation. finally, in all other cases, the day number will be used.
column 2, which I called Diff:
Last([Weight]) OVER (Intersect([Name],LastNode([Day (int)]))) -
First([Weight]) OVER (Intersect([Name],FirstNode([Day (int)])))
the first line uses what's called an OVER expression to retrieve the first value for [Weight], ordered by [Day (int)], per [Name]. the second line gives the reverse of that, and so the difference is calculated as -4 (or whatever is appropriate).

Sum unique values based on another column

I have four values: Name, Maturity, Hasinteracted?, SizeofName
Entity (Constant) - represents the name of the entity.
Maturity (Variable) - In months, how long have they been active with us (i.e. 1 would be one month etc)
Hasinteracted? (True, False) - If yes, their value is TRUE
SizeofEntity (constant) - How large is this entity? This value varies for different Names but is constant for its' own name (i.e. Entity A will always be 12 regardless of their maturity, while Entity B will be 19 regardless of their maturity)
What I am trying to do:
Using a PivotTable, I have been able to create a table which has Maturity in the rows, and count of interactions for each maturity in the column.
The part that I am struggling with is the total SizeofEntity. Basically, I want it to sum the total SizeofEntity. The issue is that if Entity A repeats in the name section, it will double in this calculation.
Example
Entity A shows once (size = 12) in maturity 1 and maturity 2, Entity B shows once (size = 19) in maturity 1.
What I am hoping to see in the value section is the total SizeofEntity in Maturity 1 being 31 and 12 in Maturity 2, which occurs.
Now, if Entity A was to interact twice in Maturity 1, I would want the size to remain same, but the number of interactions to increase. With the way it is currently structured, because Entity A is repeated, the interaction now increases by one, but so does the size of the entity (from 31 to 43).
Is there a way to have Excel ignore the value in the SizeofEntity if the Entity name is repeated in another column, or is there another way to make this possible?
The data provided in the images is a small example. I am dealing with a much larger dataset with over 300 different names with hundreds of interactions per maturity period.
I've achieved your expected results using the following logic.
Create a column called EntityConcat on column E. With this you can detect if you have duplicate entity and maturity pairs.
I've concatented them using this formula then dragged down:
=A2&B2
In another column (F) detect if they repeat and only flag the first occurence:
=IF(COUNTIF(E$2:E2,E2)=1,1,"")
Finaly I've created another column that shows sizes for the first occurence only:
=IF(F2=1,D2,0)
Now on your pivot table you can count "SizeofEntity" for total number of occurences but should instead sum this last column's values, where no duplicate entity sizes will be found.
Hope this is what you were after.

Time period in Excel 2010

A simple question, but some quick Googling did not prove fruitful.
Basically, I have a column called "uniqueID", which is a unique identifier for all the people in my dataset. Most uniqueIDs have multiple records, because there is one record per year that the person stayed at university. What I'd like to do is create a "time period" variable, where first year, t= 1, second year t=2, third year t=3 etc. for each unique ID.
The following is faster IF YOUR SPREADSHEET IS SORTED by your unique id;
=IF(A2=A1,B1+1,1)
(assumes that above formula is in column B and that data begins on row 2)
and, of course, copied down for all rows as described above.
You will find that in a spreadsheet containing many rows that COUNTIF is very slow since you are looking up through ever-increasing range sizes.

VLOOKUP all Rows and Return all Data

I am using excel 2010. I am trying to do a VLOOKUP and retrieve all values. Here is my issue - I have data with medication frequency. The frequency is listed ones; but the frequency has more than one times. Example, freq BID (twice a day) has times 0900 and 1700. When I try to do VLOOKUP, it pulling in the first value only. How do I pull in all the values?
The function =VLOOKUP(RC[-4],Sheet3!R5C1:R38C3,3,FALSE) only pulls the first row it encounters.
However, the associated FREQ has four times and notice its only pulling 00:00:00 in the above table.
If 300285 for example represents every six hours starting at midnight then a LOOKUP function could be applied to return all four daily values at one time where these are in a single wrapped cell, such as:
="00:00:00"&CHAR(10)&"06:00:00"&CHAR(10)&"12:00:00"&CHAR(10)&"18:00:00"

Resources