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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cocomy
Resolver I
Resolver I

Produce monthly dataset by calculation

Hi All,

 

I have a list of Branch capacity with start and end date. (left)

 

I want to make monthly list by country with total capacity.

 

Is there any way I can make by calculation?(right)

 

All the best,

cocomy

 

pbdataset.PNG

2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

@cocomy

 

You can create a Calculated Table

 

From the Modelling Tab>>New Table

 

New Table =
ADDCOLUMNS (
    ADDCOLUMNS (
        GENERATE (
            SELECTCOLUMNS ( Table1, "Country", [Country] ),
            GENERATESERIES ( 1, 16 )
        ),
        "Date", EOMONTH ( DATE ( 2017, 1, 1 ), [Value] - 2 )
            + 1
    ),
    "Capacity",
    VAR Mycalc =
        CALCULATE (
            SUM ( Table1[Capacity] ),
            FILTER (
                Table1,
                Table1[Country] = EARLIER ( [Country] )
                    && Table1[Start] <= [Date]
            )
        )
    RETURN
        IF ( ISBLANK ( Mycalc ), 0, mycalc )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

@cocomy

 

Generateseries function

 

"Returns a single column table containing the values of an arithmetic series, that is, a sequence of values in which each differs from the preceding by a constant quantity. The name of the column returned is Value."

 

Since you needed 16 months (Jan 17 to April 18), I used GenerateSeries(1,16) to generate 16 rows

 

Then these were Crossjoined to each row of your existing table


Regards
Zubair

Please try my custom visuals

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

 

Here's another way.  Download the file from here.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Zubair_Muhammad
Community Champion
Community Champion

@cocomy

 

You can create a Calculated Table

 

From the Modelling Tab>>New Table

 

New Table =
ADDCOLUMNS (
    ADDCOLUMNS (
        GENERATE (
            SELECTCOLUMNS ( Table1, "Country", [Country] ),
            GENERATESERIES ( 1, 16 )
        ),
        "Date", EOMONTH ( DATE ( 2017, 1, 1 ), [Value] - 2 )
            + 1
    ),
    "Capacity",
    VAR Mycalc =
        CALCULATE (
            SUM ( Table1[Capacity] ),
            FILTER (
                Table1,
                Table1[Country] = EARLIER ( [Country] )
                    && Table1[Start] <= [Date]
            )
        )
    RETURN
        IF ( ISBLANK ( Mycalc ), 0, mycalc )
)

Regards
Zubair

Please try my custom visuals

@cocomy

 

Please see attached file

 

coco.png


Regards
Zubair

Please try my custom visuals

Hi Zubair,

 

Thank you very much for your reply and apology for late.

 

Could you please help me to understand

 

GenerateSeries(1,16)

 

I see Value in new table end by 16 too.

 

All the best,

cocomy

 

 

@cocomy

 

Generateseries function

 

"Returns a single column table containing the values of an arithmetic series, that is, a sequence of values in which each differs from the preceding by a constant quantity. The name of the column returned is Value."

 

Since you needed 16 months (Jan 17 to April 18), I used GenerateSeries(1,16) to generate 16 rows

 

Then these were Crossjoined to each row of your existing table


Regards
Zubair

Please try my custom visuals

Hi Zubair,

 

Thank you for helping me out on this.

I would like to add branch by using addcolumns. I tried to insert ADDCOLUMNS(Table1,"Branch",[Branch])

into your calculation but received various error messages.(ie. Branch already exist.)

Where should I insert Branch in your DAX fomular and how?

 

New Table =
ADDCOLUMNS (
    ADDCOLUMNS (
        GENERATE (
            SELECTCOLUMNS ( Table1, "Country", [Country] ),
            GENERATESERIES ( 1, 16 )
        ),
        "Date", EOMONTH ( DATE ( 2017, 1, 1 ), [Value] - 2 )
            + 1
    ),
    "Capacity",
    VAR Mycalc =
        CALCULATE (
            SUM ( Table1[Capacity] ),
            FILTER (
                Table1,
                Table1[Country] = EARLIER ( [Country] )
                    && Table1[Start] <= [Date]
            )
        )
    RETURN
        IF ( ISBLANK ( Mycalc ), 0, mycalc )
)

 

All the best,

cocomy

Thank you so much! I could not figure that is the number if months.

All thebes
cocomy

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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