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
moussab_orabi
Frequent Visitor

Manipulating data form.

Hello every one, I need help with manipulating this data:
odred    quantity     valid_form      valid_to 

1             100            01.01.2016     31.05.2017

2              50             01.02.2016     30.06.2016

3              250            01.03.2015    31.01.2017

 

I want to accumulate the quantity per year for each order, so the data will be like following.

 

odred    quantity     valid_form    valid_to          year         year_portion 

1             100            01.01.2016     31.05.2017       2016        70.59

1             100            01.01.2016     31.05.2017       2017        29.41

2              50             01.02.2016     30.06.2016       2016        50

3              250            01.03.2015    31.01.2017       2015        108.7

3              250            01.03.2015    31.01.2017       2016        130.43

3              250            01.03.2015    31.01.2017       2017        10.87


any ideas to do that please?

 

2 ACCEPTED SOLUTIONS

@moussab_orabi

 

Following are the steps

 

Step#1 Create a New Table

 

Go to Modelling Tab >>>NEW TABLE

 

New_Table =
GENERATE (
    TableName,
    GENERATESERIES (
        YEAR ( TableName[Valid From] ),
        YEAR ( TableName[Valid To] ),
        1
    )
)

 

Step# 2 Change the Column Name from "Value" to YEAR


Regards
Zubair

Please try my custom visuals

View solution in original post

@moussab_orabi

 

Step # 3 Add the YEAR PORTION column to this NEW TABLE

 

Year_Portion =
IF (
    YEAR ( 'New_Table'[Valid From] ) = 'New_Table'[YEAR],
    DIVIDE (
        DATEDIFF (
            'New_Table'[Valid From],
            MIN ( DATE ( YEAR ( 'New_Table'[Valid From] ), 12, 31 ), 'New_Table'[Valid To] ),
            DAY
        ),
        DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY )
    ),
    IF (
        'New_Table'[YEAR] > YEAR ( 'New_Table'[Valid From] )
            && 'New_Table'[YEAR] < YEAR ( 'New_Table'[Valid To] ),
        365 / DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY ),
        DIVIDE (
            DATEDIFF (
                DATE ( YEAR ( 'New_Table'[Valid to] ) - 1, 12, 31 ),
                'New_Table'[Valid To],
                DAY
            ),
            DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY )
        )
    )
)
    * 'New_Table'[Quantity]

Regards
Zubair

Please try my custom visuals

View solution in original post

7 REPLIES 7
Zubair_Muhammad
Community Champion
Community Champion

@jthomson

 

Thanks Smiley Very Happy. I had missed it

 

@moussab_orabi

 

See the attached file here with the solution or attempted solution

 

 

 

 


Regards
Zubair

Please try my custom visuals

@moussab_orabi

 

Following are the steps

 

Step#1 Create a New Table

 

Go to Modelling Tab >>>NEW TABLE

 

New_Table =
GENERATE (
    TableName,
    GENERATESERIES (
        YEAR ( TableName[Valid From] ),
        YEAR ( TableName[Valid To] ),
        1
    )
)

 

Step# 2 Change the Column Name from "Value" to YEAR


Regards
Zubair

Please try my custom visuals

Hello Zubair,
thanks for your solution it was really helpful,
GENERATE_SERIES was the missing operation I needed.

BR,
Moussab

@moussab_orabi

 

Step # 3 Add the YEAR PORTION column to this NEW TABLE

 

Year_Portion =
IF (
    YEAR ( 'New_Table'[Valid From] ) = 'New_Table'[YEAR],
    DIVIDE (
        DATEDIFF (
            'New_Table'[Valid From],
            MIN ( DATE ( YEAR ( 'New_Table'[Valid From] ), 12, 31 ), 'New_Table'[Valid To] ),
            DAY
        ),
        DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY )
    ),
    IF (
        'New_Table'[YEAR] > YEAR ( 'New_Table'[Valid From] )
            && 'New_Table'[YEAR] < YEAR ( 'New_Table'[Valid To] ),
        365 / DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY ),
        DIVIDE (
            DATEDIFF (
                DATE ( YEAR ( 'New_Table'[Valid to] ) - 1, 12, 31 ),
                'New_Table'[Valid To],
                DAY
            ),
            DATEDIFF ( 'New_Table'[Valid From], 'New_Table'[Valid To], DAY )
        )
    )
)
    * 'New_Table'[Quantity]

Regards
Zubair

Please try my custom visuals

@moussab_orabi

 

Final output looks like this

 

It would be in accurate by decimals. I think because DateDiff formula misses one Day i..e to say Datediff between 1 Jan and 31 Dec is 364 days.

 

4000.png


Regards
Zubair

Please try my custom visuals
Zubair_Muhammad
Community Champion
Community Champion

@moussab_orabi

 

How is the year portion computed for 2 and 3

 

Shouldn't this total upto 100 like in case of 1


Regards
Zubair

Please try my custom visuals

Looks like it's relative to the quantity and not a percentage

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.