cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

Create new table: calculate min date of all the dates per record

I have a table with records including multiple dates per record. One person had multiple transactions on multip[le dates. I have to find the min date, first date of transaction and last date of transaction and the amount withdrawn/deposited on those 2 transactions.

I am open to crreating 2 separate tables saying first transaction and last transaction. or having 1 table with both the information.

When I am using min date funstion its giving me min of the date column and not per record.

Any help is much appreciated

1 ACCEPTED SOLUTION
Impactful Individual

Ok I have no idea what your ideal outcome is... I thought a derived table was the objective, how did it become a workaround?

Use the Relationships tab in PowerBI to create the relationship. EmpID isn't a primary key in the initial table because it has duplicates, but it's unique in the second table so should be fine.

18 REPLIES 18
Employee

@rpratibha86

Your requirement is not quite clear for me, based on my understanding, are you looking for something like nested IFs?

```minDate =
IF (
'table'[date4]
> IF (
IF ( 'table'[date1] > 'table'[date2], 'table'[date2], 'table'[date1] )
> 'table'[date3],
'table'[date3],
IF ( 'table'[date1] > 'table'[date2], 'table'[date2], 'table'[date1] )
),
IF (
IF ( 'table'[date1] > 'table'[date2], 'table'[date2], 'table'[date1] )
> 'table'[date3],
'table'[date3],
IF ( 'table'[date1] > 'table'[date2], 'table'[date2], 'table'[date1] )
),
'table'[date4]
)```
```maxDate =
IF (
'table'[date4]
< IF (
IF ( 'table'[date1] < 'table'[date2], 'table'[date2], 'table'[date1] )
< 'table'[date3],
'table'[date3],
IF ( 'table'[date1] < 'table'[date2], 'table'[date2], 'table'[date1] )
),
IF (
IF ( 'table'[date1] < 'table'[date2], 'table'[date2], 'table'[date1] )
< 'table'[date3],
'table'[date3],
IF ( 'table'[date1] < 'table'[date2], 'table'[date2], 'table'[date1] )
),
'table'[date4]
)```

Alternatively, you can unpivot the date columns and use MAX and MIN.

Frequent Visitor

Hi,

I have an unpivoted date column table only and when i use Max and Min its calculating the min and max of all records and not per record . but the desired output is the same liek your screen shot.

Impactful Individual

Can you add a column to the table with something like this formula?

MinDate = CALCULATE(MIN(Table1[Date]), ALL(Table1), Table1[person] = EARLIER(Table1[person]))

MaxDate = CALCULATE(MAX(Table1[Date]), ALL(Table1), Table1[person] = EARLIER(Table1[person]))

Frequent Visitor

getting the following error message:

"A single value for column 'date' in table 'table1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

Impactful Individual

Can you paste in your exact formula?

EDIT: Just reread the error, looks like you're making it as a measure. You need to make it as a new Table, not a new Measure.

Frequent Visitor

As a  workaround I created a derived table only with Emp Id, firsttransaction date , Last Transaction date.

but I want to pull the dates from this table and amount from the parent table but its not letting me pull any column from parent table. How do I create a relation between the two, as EmpId is Primary key for both the tables

Frequent Visitor

That works..All ypour help is much appreciated!

Impactful Individual

Ok I have no idea what your ideal outcome is... I thought a derived table was the objective, how did it become a workaround?

Use the Relationships tab in PowerBI to create the relationship. EmpID isn't a primary key in the initial table because it has duplicates, but it's unique in the second table so should be fine.

Frequent Visitor

Actually I was trying to pull all the data fields in one table including min and max dates. But If I do so I am getting duplicates as its pulling all the records.

So the workaround is:Pulling only EmpId, Mindate and Max date in one table. Then Link it to parent table and create reports.

But I could not figure out a way to create a link or relationship between the derived table and the parent table.

My apologies for any confusion , I am very new to POwer BI, trying to work it out.

@rpratibha86 wrote:

When I am using min date funstion its giving me min of the date column and not per record.

The formula will operate over the filter context.  If you select a single person, it should give max and min for them. If you select all people, it should give min and max for all people. The correct formula depends on what you are trying to achieve. If you can post samples of your desired output and your table structure, I can give you more guidance.

* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
Frequent Visitor

I am trying to Achineve some thing like this:

Impactful Individual

If you're set on a new table, you can use SUMMARIZE to create it:

NewTable = SUMMARIZE(Data, Data[Emp ID], "FirstTransactionDate", MIN(Data[Transactiondate]), "LastTransactionDate", MAX(Data[Transactiondate]))

Frequent Visitor

Tried this solution but its not working..still pulling up all the rows.

Responsive Resident

instead of creating new tables you should try DAX functions FIRSTDATE and LASTDATE.

Frequent Visitor

I was able to pick min and max dates using firstdate and last date, is there way I can pull the corresponsing transaction amount, like the amount on first date and amount on last date

Impactful Individual

Use the LOOKUPVALUE function. You could use extra clauses in the SUMMARIZE function but it's probably easier to make a new column like:

FirstAmount = LOOKUPVALUE(Data[Amount], Data[Transactiondate], NewTable[FirstTransactionDate])

Similar for LastAmount.

Frequent Visitor

I am getting the following error:

A table of multiple values was supplied where a single value was expected.

Impactful Individual

Oh wow, I'm not very smart, sorry.

FirstAmount = LOOKUPVALUE(Data[Amount], Data[Transactiondate], NewTable[FirstTransactionDate], Data[Emp ID], NewTable[Emp ID])

Announcements

Fabric certifications survey

Certification feedback opportunity for the community.

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors