Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Reffering to [Value] of GENERATESERIES within Variables

I have a table that contains transactions done by users. Beside the user and the date, the transaction was created on, the table contains several other information like the users team lead, the project and process the transaction was made for, etc.

 

I now want to create a measure that calculates the average amount of transactions created within a selected periode by users with the same attribute (same project, same team lead, etc.). So the basic calculation would be (average transactions per day) / (average amount of users per day).

This is my approach:

av_Transactions_timeperiode = 

VAR start_date = IF(ISBLANK(MIN('Merged Data'[Created_Date])),0,MIN('Merged Data'[Created_Date]))
VAR end_date = IF(ISBLANK(MAX('Merged Data'[Created_Date])),1,MAX('Merged Data'[Created_Date]))

VAR __dates = GENERATESERIES(start_date,end_date)

VAR __trans_users = ADDCOLUMNS(__dates,
                                "Transactions",
                                CALCULATE(COUNT('Merged Data'[TransactionID]),'Merged Data'[Created_Date] = [Value]),
                                "Users",
                                CALCULATE(DISTINCTCOUNT('Merged Data'[User]),'Merged Data'[Created_Date] = [Value])
                            )

VAR av_transactions = AVERAGEX(__trans_users,[Transactions])
VAR av_users = AVERAGEX(__trans_users,[Users])

VAR av_trans_per_user = av_transactions/av_users

RETURN av_trans_per_user


However this doesn't work. Within the ADDCOLUMNS I can reffer to the [Value] of __dates but as soon as I want to reffer to it within the CALCULATE function it cannot be found. There is no difference when I try to use "__dates[Value]" instead, as __dates is a variable and not a "manifestated" table.

Is there any option I could reffer to the [Value] of __dates within the CALCULATE function? Or is there another approach to calculate the data I want?

If needed: The table "Merged Data" is sliced by a seperate date table that is related via the "Created_Date" column.

Thanks in advance

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 

please try

av_Transactions_timeperiode =
VAR start_date =
COALESCE ( MIN ( 'Merged Data'[Created_Date] ), 0 )
VAR end_date =
COALESCE ( MAX ( 'Merged Data'[Created_Date] ), 1 )
VAR __dates =
CALENDAR ( start_date, end_date )
VAR __trans_users =
GENERATE (
__dates,
VAR CurrentDate = [Date]
VAR Transactions =
CALCULATE (
COUNT ( 'Merged Data'[TransactionID] ),
'Merged Data'[Created_Date] = CurrentDate
)
VAR Users =
CALCULATE (
DISTINCTCOUNT ( 'Merged Data'[User] ),
'Merged Data'[Created_Date] = CurrentDate
)
RETURN
ROW ( "Transactions", Transactions, "Users", Users )
)
VAR av_transactions =
AVERAGEX ( __trans_users, [Transactions] )
VAR av_users =
AVERAGEX ( __trans_users, [Users] )
VAR av_trans_per_user = av_transactions / av_users
RETURN
av_trans_per_user

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Anonymous 

please try

av_Transactions_timeperiode =
VAR start_date =
COALESCE ( MIN ( 'Merged Data'[Created_Date] ), 0 )
VAR end_date =
COALESCE ( MAX ( 'Merged Data'[Created_Date] ), 1 )
VAR __dates =
CALENDAR ( start_date, end_date )
VAR __trans_users =
GENERATE (
__dates,
VAR CurrentDate = [Date]
VAR Transactions =
CALCULATE (
COUNT ( 'Merged Data'[TransactionID] ),
'Merged Data'[Created_Date] = CurrentDate
)
VAR Users =
CALCULATE (
DISTINCTCOUNT ( 'Merged Data'[User] ),
'Merged Data'[Created_Date] = CurrentDate
)
RETURN
ROW ( "Transactions", Transactions, "Users", Users )
)
VAR av_transactions =
AVERAGEX ( __trans_users, [Transactions] )
VAR av_users =
AVERAGEX ( __trans_users, [Users] )
VAR av_trans_per_user = av_transactions / av_users
RETURN
av_trans_per_user

Anonymous
Not applicable

Thanks @tamerj1 ,

 

this works as intended.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.