March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Solved! Go to Solution.
hello @phorfanos
can you please check this measure :
link to download file from :
https://drive.google.com/file/d/1FI-fqw3eB5vGo9lA1dgTzfRR-Vi3adCz/view?usp=sharing
summary :
1.create dimdate
2.create dimagent
3.link both tables to Table4 (the table that contains the transactional data )
4. write the measure : days since next trans - measure ( this calculates the average )
model :
output :
days since next trans - measure =
var current_date = MAX(Table4[Transaction Date])
var c = CALCULATE(COUNT(Table4[Transaction Date]) )
var datasource =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource1 =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource2 =
ADDCOLUMNS(
ADDCOLUMNS(
datasource1,
"prev_date",
SELECTCOLUMNS(
offset(
1,
,ORDERBY(dimdate[Date], desc)
),
"prev_date", dimdate[Date]
)
),
"diff", DATEDIFF([prev_date], dimdate[Date],DAY)
)
var res = SUMx(datasource2 , [diff]) / c
return if( current_date in VALUES(Table4[Transaction Date]), res)
let ne know if it works for you .
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅!
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠
use this code instead :
(just some minor changes from the above code and removing some unecessary code ) .
days since next trans - measure =
var current_date = MAX(Table4[Transaction Date])
var c = CALCULATE(COUNT(Table4[Transaction Date]) )
var datasource1 =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource2 =
ADDCOLUMNS(
ADDCOLUMNS(
datasource1,
"prev_date",
SELECTCOLUMNS(
offset(
1,
,ORDERBY(dimdate[Date], desc)
),
"prev_date", dimdate[Date]
)
),
"diff", DATEDIFF([prev_date], dimdate[Date],DAY)
)
var res = SUMx(datasource2 , [diff]) / c
return
res
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅!
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠
hello @phorfanos
are you able to show at least a sample data for 1 transaction with the table sturcture, (a screenshot would be enough just to make sense of what you want to achieve.
Here an example for 1 agent A with 9 transactions during the last year:
Transaction Date | Days since next transaction |
7/31/2023 | 0 |
8/11/2023 | 11 |
8/14/2023 | 3 |
8/16/2023 | 2 |
8/17/2023 | 1 |
8/19/2023 | 2 |
8/30/2023 | 11 |
9/5/2023 | 6 |
9/15/2023 | 10 |
For example it took 11 days to retransact the first time (from 31st July 2023 to 11th August 2023. And then the mean days for transacton is equal to 5.11. On average, this agent makes a transaction every 5.11 days. I hope it is clearer now.
When I insert the second measure (mean) in a table with all agents, it takes a long time to get results. Ideally I would like to have the following table:
Agent | Mean of days between transactions |
A | 5.11 |
B | ? |
C | ? |
... | ... |
Hi @phorfanos ,
I have created simple samples and you can check the results below:
Measure = VAR _T = ADDCOLUMNS('Table',"AVG",AVERAGEX(FILTER(ALL('Table'),[Type]=EARLIER([Type])),[Days since next transaction]))
RETURN MAXX(_T,[AVG])
An attachment for your reference. Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for your reply! Actually my formula (
DaysBetweenTransactionDates =
VAR CurrentDate = MAX(Tickets[Transaction Date])
VAR PriorDate = CALCULATE(MAX(Tickets[Transaction Date]), FILTER(ALLSELECTED(Tickets), Tickets[Transaction Date] <CurrentDate))
VAR MinDate = CALCULATE(MIN(Tickets[Transaction Date]), ALLSELECTED(Tickets))
VAR Difference = datediff(PriorDate,CurrentDate,day)
VAR Result = IF(CurrentDate = MinDate, 0, Difference)
RETURN Result
but this had a minor impact to optimization..
hello @phorfanos
can you please check this measure :
link to download file from :
https://drive.google.com/file/d/1FI-fqw3eB5vGo9lA1dgTzfRR-Vi3adCz/view?usp=sharing
summary :
1.create dimdate
2.create dimagent
3.link both tables to Table4 (the table that contains the transactional data )
4. write the measure : days since next trans - measure ( this calculates the average )
model :
output :
days since next trans - measure =
var current_date = MAX(Table4[Transaction Date])
var c = CALCULATE(COUNT(Table4[Transaction Date]) )
var datasource =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource1 =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource2 =
ADDCOLUMNS(
ADDCOLUMNS(
datasource1,
"prev_date",
SELECTCOLUMNS(
offset(
1,
,ORDERBY(dimdate[Date], desc)
),
"prev_date", dimdate[Date]
)
),
"diff", DATEDIFF([prev_date], dimdate[Date],DAY)
)
var res = SUMx(datasource2 , [diff]) / c
return if( current_date in VALUES(Table4[Transaction Date]), res)
let ne know if it works for you .
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅!
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠
Yes, definitely this measure is way much better than mine and produces results much faster! I just replaces the 2nd line "
var c = CALCULATE(COUNT(Table4[Transaction Date]) )
to
var c = CALCULATE(DISTINCTCOUNT(Table4[Transaction Date]) )
But I will work on it a little bit more to optimize it further. Dear @Daniel29195 thnx a lot for your consideration and the time spent!
use this code instead :
(just some minor changes from the above code and removing some unecessary code ) .
days since next trans - measure =
var current_date = MAX(Table4[Transaction Date])
var c = CALCULATE(COUNT(Table4[Transaction Date]) )
var datasource1 =
CALCULATETABLE(
SUMMARIZE(
table4,
dimagent[Agent],
dimdate[Date]
),
ALL(dimdate),
dimdate[Date] <=current_date
)
var datasource2 =
ADDCOLUMNS(
ADDCOLUMNS(
datasource1,
"prev_date",
SELECTCOLUMNS(
offset(
1,
,ORDERBY(dimdate[Date], desc)
),
"prev_date", dimdate[Date]
)
),
"diff", DATEDIFF([prev_date], dimdate[Date],DAY)
)
var res = SUMx(datasource2 , [diff]) / c
return
res
If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution ✅!
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠
@phorfanos understood.
did you debug your code .
by that i mean, did you try, to first measure in the table visual, and check if you have performance issue.
then in measure 1, try to return the variables, and check on which variable the performance issue happen .
if you want, and possible for youm i dont have a problem going via zoom, to check it with you via a call .
best regards.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
125 | |
85 | |
69 | |
54 | |
45 |
User | Count |
---|---|
204 | |
106 | |
98 | |
65 | |
54 |