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

Be 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

Reply
cinlod
Frequent Visitor

Dax formula for counting and grouping weekly transactions by frequency

Hi,

 

Please, i need help. Need a DAX formula 

 

I have over 100 different services in a daily transaction record. I want to count and group each service by frequency by 1 Transaction, 2 Transactions, 3 Transactions, 4 Transactions, above 4 Transactions on a weekly basis. In order to plot visuals.

 

 

Many Thanks

1 ACCEPTED SOLUTION


@cinlod wrote:

Hi Fhill,

 

Your output is wonderful. I which to get a weekly result of this output such that if i group the frequency into, Example:

 

Week "X"                      Frequency (Total count)

1 Transaction                  23

2 Transactions                 12

3 Transactions                  7

4 Transactions                  4

Above 4 Transactions       1

 

Many Thanks,


@cinlod

To  get the expected output, you may have to create an auxiliary table as below

Capture.PNG

 

Then create a measure as 

Frequency (Total count) =
VAR summizedTable =
    SUMMARIZE (
        yourTable,
        yourTable[Vehicle Number],
        "transaction cnt", COUNT ( yourTable[Vehicle Number] )
    )
VAR addcolumn =
    ADDCOLUMNS (
        summizedTable,
        "frequence", SWITCH (
            TRUE (),
            [transaction cnt] = 1, "1 Transaction",
            [transaction cnt] = 2, "2 Transactions",
            [transaction cnt] = 3, "3 Transactions",
            [transaction cnt] = 4, "4 Transactions",
            "Above 4 Transactions"
        )
    )
RETURN
    COUNTROWS (
        FILTER ( addcolumn, [frequence] = MAX ( FrequenceTbl[Frequence] ) )
    )

So finally

Capture.PNG

 

See more in the attached pbix file.

View solution in original post

6 REPLIES 6
fhill
Resident Rockstar
Resident Rockstar

Could you please post some sample raw data, and a mock up of your desired output?  Thank You




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




cinlod
Frequent Visitor

Hi Fhill,

 

Thanks for your response.

 

Please, kindly find attached sample data. I want to count the frequency of Vehicle Numble and group the frequency into 1 Transaction, 1 Transaction, 2 Transactions, 3 Transactions, and Above 4 Transactions.

 

Many Thanks

 

Transport/
D-Note No
Volume (t)KmVehicle NumberDateDriverRegionWeekFreight Cost
0111529080130101AA464MDG42739ABUBAKAR INUSANorth East276041.79
0111546570130627AA343NFD42757UMAR ISAHNorth West4267867
0111531710130402AA340NFD42742ABDULLAHI MOHDNorth West2207682
0111535960130402AA340NFD42746adamu aliNorth West3207682
0111539240130402AA340NFD42748SULE AHMADNorth West3207682
0082431810140147AAA107XN42756TN-009302325/JUDE IYORIOBHEWest4184683.2
0093010760140330AAA107XN42748JUDE IYORISouth West3304498.4
0093011570130155AAA205XA42748SULAIMON QUADRIWest3105346.6
0093011960130107AAA135XP42748TN-008242203-KAZEEM LATEEFLagos Mainland3107417.5
009301887014070AAA107XN42754JUDE IYORIOBHELagos Island4156938.4
010142202013084.2AAA155XN42739ABIODUN LAWALWest2102009.6
010142268013080.4AAA205XA42740SULAIMAN QUADRIWest2102009.6
010142462013080.4AAA205XA42743SULAIMANWest2102009.6
010142471013018.3AAA155XN42743abiodun lawalWest266162.51
0101428490129.3168.8AAA10XK42748RASHEED SHARAFALagos Island384916.65
0101429390132.7868.8AAA10XK42750RASHEED SHARAFALagos Island384916.65
010143031013059AAA155XN42752ABIODUN LAWALWest462400.25
010143234013043AAA205XA42753SULE QUADRILagos Mainland466162.51

@cinlod

 

Do you need output like this?

 

Grouping by Frequency.jpg

Hi Fhill,

 

Your output is wonderful. I which to get a weekly result of this output such that if i group the frequency into, Example:

 

Week "X"                      Frequency (Total count)

1 Transaction                  23

2 Transactions                 12

3 Transactions                  7

4 Transactions                  4

Above 4 Transactions       1

 

Many Thanks,


@cinlod wrote:

Hi Fhill,

 

Your output is wonderful. I which to get a weekly result of this output such that if i group the frequency into, Example:

 

Week "X"                      Frequency (Total count)

1 Transaction                  23

2 Transactions                 12

3 Transactions                  7

4 Transactions                  4

Above 4 Transactions       1

 

Many Thanks,


@cinlod

To  get the expected output, you may have to create an auxiliary table as below

Capture.PNG

 

Then create a measure as 

Frequency (Total count) =
VAR summizedTable =
    SUMMARIZE (
        yourTable,
        yourTable[Vehicle Number],
        "transaction cnt", COUNT ( yourTable[Vehicle Number] )
    )
VAR addcolumn =
    ADDCOLUMNS (
        summizedTable,
        "frequence", SWITCH (
            TRUE (),
            [transaction cnt] = 1, "1 Transaction",
            [transaction cnt] = 2, "2 Transactions",
            [transaction cnt] = 3, "3 Transactions",
            [transaction cnt] = 4, "4 Transactions",
            "Above 4 Transactions"
        )
    )
RETURN
    COUNTROWS (
        FILTER ( addcolumn, [frequence] = MAX ( FrequenceTbl[Frequence] ) )
    )

So finally

Capture.PNG

 

See more in the attached pbix file.

@Eric_Zhang This was very helpful. I think I'm on the right track now. I just wish I understood what each DAX expression was doing, so I could absorb this better. Thank you very much!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.